{"id":15740937,"url":"https://github.com/jossmac/react-pseudo-state","last_synced_at":"2025-03-13T09:32:26.143Z","repository":{"id":57342830,"uuid":"131559343","full_name":"jossmac/react-pseudo-state","owner":"jossmac","description":"🎛 Stateful pseudo-classes in React","archived":false,"fork":false,"pushed_at":"2019-03-08T08:09:51.000Z","size":204,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-26T19:46:52.837Z","etag":null,"topics":["css-in-js","pseudo-classes","react"],"latest_commit_sha":null,"homepage":"https://jossmac.github.io/react-pseudo-state","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jossmac.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-30T05:30:58.000Z","updated_at":"2023-08-18T10:10:13.000Z","dependencies_parsed_at":"2022-09-16T02:50:32.205Z","dependency_job_id":null,"html_url":"https://github.com/jossmac/react-pseudo-state","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jossmac%2Freact-pseudo-state","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jossmac%2Freact-pseudo-state/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jossmac%2Freact-pseudo-state/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jossmac%2Freact-pseudo-state/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jossmac","download_url":"https://codeload.github.com/jossmac/react-pseudo-state/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243377725,"owners_count":20281279,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["css-in-js","pseudo-classes","react"],"created_at":"2024-10-04T02:41:22.799Z","updated_at":"2025-03-13T09:32:25.807Z","avatar_url":"https://github.com/jossmac.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# React Pseudo State\n\nThe solution for handling pseudo-states when working with a CSS in JS solution.\n\n[![Build Status](https://travis-ci.org/jossmac/react-pseudo-state.svg?branch=master)](https://travis-ci.org/jossmac/react-pseudo-state)\n\n### Install\n\n```bash\nyarn add react-pseudo-state\n```\n\n### Use\n\n```jsx\nimport { PseudoState } from 'react-pseudo-state';\n\nconst Button = ({ children, ...props }) =\u003e (\n  \u003cPseudoState\u003e\n    {(handlers, snapshot) =\u003e (\n      \u003cbutton\n        css={{\n          background: snapshot.isHover ? 'lightBlue' : 'blue',\n          color: snapshot.isActive ? 'slateGray' : 'lightSlateGray',\n          outline: snapshot.isFocus \u0026\u0026 snapshot.focusOrigin === 'keyboard'\n            ? '3px dotted blue'\n            : null,\n        }}\n        {...props}\n        {...handlers}\n      \u003e\n        {children}\n      \u003c/button\u003e\n    )}\n  \u003c/PseudoState\u003e\n);\n```\n\nA higher-order-component is also provided if that's more your speed:\n\n```jsx\nimport { withPseudoState } from 'react-pseudo-state';\n\nconst ButtonElement = ({ isActive, ...props }) =\u003e (\n  \u003cbutton css={{ color: isActive ? 'slateGray' : 'lightSlateGray' }} {...props} /\u003e\n);\n\nexport const Button = withPseudoState(ButtonElement);\n```\n\n### Keyboard support\n\nThe native browser behaviour is that `Enter` is for anchors and buttons, whilst `Space` is only called on buttons. To stay compliant it's recommended to dynamically populate the `keyboardSupport` property.\n\nThe shape of `keyboardSupport` is described below in the [Types section](#types). It will default to `'auto'`, which sniffs the event target for a node type.\n\n```jsx\nimport { PseudoState } from 'react-pseudo-state';\n\nconst Button = (props) =\u003e (\n  \u003cPseudoState keyboardSupport={props.href ? 'enter' : 'both'}\u003e\n    {(handlers, snapshot) =\u003e props.href ? \u003ca /\u003e : \u003cbutton /\u003e)}\n  \u003c/PseudoState\u003e\n);\n```\n\n### Types\n\nThe first argument to the `children` function is an object of handlers, which must be spread onto the node returned from `children`:\n\n```jsx\ntype Handlers = {\n  onBlur: () =\u003e mixed,\n  onFocus: () =\u003e mixed,\n  onKeyDown?: (event: SyntheticKeyboardEvent\u003cHTMLElement\u003e) =\u003e mixed,\n  onKeyUp?: (event: SyntheticKeyboardEvent\u003cHTMLElement\u003e) =\u003e mixed,\n  onMouseDown: () =\u003e mixed,\n  onMouseEnter: () =\u003e mixed,\n  onMouseLeave: () =\u003e mixed,\n  onMouseUp: () =\u003e mixed,\n  onTouchEnd: () =\u003e mixed,\n  onTouchStart: () =\u003e mixed,\n};\n```\n\nThe second argument is the snapshot, or current state of the element:\n\n```jsx\ntype Snapshot = {\n  focusOrigin: null | 'keyboard' | 'mouse',\n  isActive: boolean,\n  isFocus: boolean,\n  isHover: boolean,\n};\n```\n\nThe actual `PseudoState` component only has two properties:\n\n```jsx\ntype Props = {\n  children: (Handlers, Snapshot) =\u003e React$Node,\n  keyboardSupport: 'auto' | 'enter' | 'space' | 'both' | 'none',\n};\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjossmac%2Freact-pseudo-state","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjossmac%2Freact-pseudo-state","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjossmac%2Freact-pseudo-state/lists"}