{"id":28284732,"url":"https://github.com/danieljharvey/purescript-react-stylesheet","last_synced_at":"2025-08-24T16:34:34.573Z","repository":{"id":51772440,"uuid":"199017260","full_name":"danieljharvey/purescript-react-stylesheet","owner":"danieljharvey","description":"Utilities to attach purescript-stylesheet to purescript-react","archived":false,"fork":false,"pushed_at":"2021-05-10T04:01:15.000Z","size":21,"stargazers_count":7,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-21T20:09:12.244Z","etag":null,"topics":["css","purescript","purescript-react","react","stylesheet","styling"],"latest_commit_sha":null,"homepage":null,"language":"PureScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danieljharvey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-26T13:00:32.000Z","updated_at":"2019-10-29T19:28:44.000Z","dependencies_parsed_at":"2022-08-22T19:40:47.399Z","dependency_job_id":null,"html_url":"https://github.com/danieljharvey/purescript-react-stylesheet","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/danieljharvey/purescript-react-stylesheet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danieljharvey%2Fpurescript-react-stylesheet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danieljharvey%2Fpurescript-react-stylesheet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danieljharvey%2Fpurescript-react-stylesheet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danieljharvey%2Fpurescript-react-stylesheet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danieljharvey","download_url":"https://codeload.github.com/danieljharvey/purescript-react-stylesheet/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danieljharvey%2Fpurescript-react-stylesheet/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271902915,"owners_count":24841280,"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","status":"online","status_checked_at":"2025-08-24T02:00:11.135Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","purescript","purescript-react","react","stylesheet","styling"],"created_at":"2025-05-21T17:14:45.044Z","updated_at":"2025-08-24T16:34:34.566Z","avatar_url":"https://github.com/danieljharvey.png","language":"PureScript","readme":"# purescript-react-stylesheet\n\nUtilities to use [Purescript Stylesheet](https://github.com/danieljharvey/purescript-stylesheet) with [Purescript React](https://github.com/purescript-contrib/purescript-react). Demo app [here](https://github.com/danieljharvey/purescript-stylesheet-example).\n\nPurescript Stylesheet is a Virtual Stylesheet that allows you to dynamically add styles to a CSS Stylesheet. This library provides components that provide and consume a Virtual Stylesheet via React Context.\n\n### What?\n\nPurescript Stylesheet allows you to create styles for your app that change depending on state. You provide functions from `props` to `CSS` and Stylesheet takes care of plopping them into a real stylesheet in your browser and making things look nice.\n\n### Like Styled Components?\n\nYeah, that kind of thing. The ideas in this library aren't really new, I just wanted something like this in Purescript.\n\n### How do I use it then?\n\nGood question.\n\nWe'll start by creating a `StyleContext`.\n\n```haskell\nimport React.Stylesheet\n\nstyleContext :: StyleContext\nstyleContext \n  = createStyleContext (SProxy :: SProxy \"hey-nice-styles-buddy\")\n```\n\nThis contains three things - \n\n1. Provider - a React class that provides the Stylesheet superpowers via React Context.\n2. Consumer - a React class that can be used to consume the Stylesheet superpowers\n3. Elements - a big pile of pre-wrapped DOM elements that will probably be the most useful part.\n\nWe need to put the `Provider` at the tree of our app.\n\n```haskell\nmainClass :: React.ReactClass { }\nmainClass = React.component \"Main\" component\n  where\n  component this =\n    pure { state: {\n            { todos: []\n            }\n         , render: pure \n            $ React.createLeafElement styleContext.provider\n              { children: [ render ] }\n         }\n    where\n    render state = ...\n```\n\nIn this example the `render` function then takes care of the rest of your app.\n\n### What now?\n\nLet's make an element with styles!\n\nWe define styles with a `CSSRuleSet`. It takes a type that defines the props it can receive. Here is one that takes no props (which we represent with `unit`).\n\n```haskell\ncontainerStyle :: CSSRuleSet Unit\ncontainerStyle\n  = str \"\"\"\n      margin: 20px;\n      padding: 20px;\n      border-radius: 10px;\n      display: flex;\n      flex-direction: row;\n      justify-content: center;\n    \"\"\"\n```\n\nWe are using Purescript's triple quote thing to smash a big lump of stupid CSS into a `CSSRuleSet`. Now let's give them to an element...\n\n```haskell\ncontainer :: Array Props -\u003e Array ReactElement -\u003e ReactElement\ncontainer \n  = styleContext.elements.div containerStyles unit\n```\n\nWe've taken the `div` element from our `StyleContext`, and added these styles to it. Now we can use this `container` element in our app:\n\n```haskell\nrender = container [] [ text \"I am some text in an attractive looking box\" ]\n```\n\n### Good stuff.\n\nNow, what about something smarter? Let's have something with props.\n\n```haskell\ndata TrafficLights\n  = Red\n  | Yellow\n  | Green\n\ntrafficStyle :: CSSRuleSet TrafficLights\ntrafficStyle\n  = str \"\"\"\n      border: none; \n      border-radius: 20px;\n      width: 40px;\n      height: 40px;\n      \"\"\"\n  \u003c\u003e fun (\\light -\u003e case light of\n            Red -\u003e \"background-color: red;\"\n            Yellow -\u003e \"background-color: yellow;\"\n            Green -\u003e \"background-color: green;\") \n\ntrafficLight :: TrafficLights -\u003e ReactElement\ntrafficLight colour \n  = styleContext.elements.div trafficStyle colour [] {}\n```\n\nWe have have a colour-changing traffic light!\n\n### Working example:\n\nThe full working example is [here](https://github.com/danieljharvey/purescript-stylesheet-example).\n\n### Why just Purescript React? Why not [insert thing]?\n\nIf this doesn't turn out to be an utter disaster, I would like to port it for use in React Basic and Halogen. If you are good at those things and want to help, by all means get in touch.\n\n### Why plain text CSS and not something more type-safe?\n\nThree reasons:\n\n1. Lazyness\n2. Easy to paste existing CSS in for ease of adoption\n3. Lazyness\n\n### Docs?\n\nYes, on [Pursuit](https://pursuit.purescript.org/packages/purescript-react-stylesheet/0.0.2)111","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanieljharvey%2Fpurescript-react-stylesheet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanieljharvey%2Fpurescript-react-stylesheet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanieljharvey%2Fpurescript-react-stylesheet/lists"}