{"id":15725855,"url":"https://github.com/ndrean/solid-components","last_synced_at":"2026-05-19T19:08:06.292Z","repository":{"id":164400243,"uuid":"639572352","full_name":"ndrean/Solid-components","owner":"ndrean","description":"web components powered by SolidJS with CSS in JS ","archived":false,"fork":false,"pushed_at":"2023-06-08T18:23:22.000Z","size":9502,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-31T01:28:44.370Z","etag":null,"topics":["solid-router","solid-styled","solidjs"],"latest_commit_sha":null,"homepage":"https://solid-components.surge.sh","language":"JavaScript","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/ndrean.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-11T18:34:23.000Z","updated_at":"2023-06-05T09:32:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"bc9f0c18-1213-41fb-878d-556cd172314b","html_url":"https://github.com/ndrean/Solid-components","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ndrean/Solid-components","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndrean%2FSolid-components","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndrean%2FSolid-components/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndrean%2FSolid-components/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndrean%2FSolid-components/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ndrean","download_url":"https://codeload.github.com/ndrean/Solid-components/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ndrean%2FSolid-components/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266682462,"owners_count":23967827,"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-07-23T02:00:09.312Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"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":["solid-router","solid-styled","solidjs"],"created_at":"2024-10-03T22:24:36.812Z","updated_at":"2026-05-19T19:08:06.256Z","avatar_url":"https://github.com/ndrean.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SolidJS components, CSS-in-JS and Solid-Router\n\nThis work is 100% based on [the following repo](https://github.com/FredericHeem/mdlean) adapted for SolidJS.\n\n## Some examples\n\nA Dialog/Modal component: it has an integrated \"clickOut\" function via the ID. You pass a REF reference for the \u003ccode\u003e shwoModal()\u003c/code\u003e and \u003ccode\u003e close()\u003c/code\u003e functions.\n\n```jsx\nimport dialogComponent from \"...\";\nimport button from \"...\";\nimport Unicode from \"...\";\nimport context from \"...\";\n\nconst myPage = (context) =\u003e {\n  const {codes: {cross}} = context;\n  const Dialog = dialogComponent(context);\n  const Button = button(context);\n\n  return (props) =\u003e {\n    let dialogRef;\n\n  [...]\n\n  return (\n    \u003c\u003e\n      \u003cButton fullWidth primary raised onClick={() =\u003e dialogRef.showModal()}\u003e\n        Open Modal\n      \u003c/Button\u003e\n      \u003cDialog ref={dialogRef} id=\"mod1\"\u003e\n        [...insert content here...]\n        \u003cButton primary onClick={() =\u003e dialogRef.close()}\u003e\n          \u003cUnicode size=\"1.5em\" code={cross} /\u003e\n        \u003c/Button\u003e\n      \u003c/Dialog\u003e\n    \u003c/\u003e\n  )\n }\n}\n\n\nconst MyPage = myPage(context)\n\n\u003cMyPage /\u003e\n```\n\n## Example with Routing\n\n```jsx\nimport { useRouteData, useRoutes, A } from \"@solidjs/router\";\nimport { styled } from \"solid-styled-components\";\n\nconst routeExample = [\n  {\n    path: \"/api\",\n    title: \"Api\",\n    data: () =\u003e \"ok\",\n    component: lazy(() =\u003e import(\"./app/pages/apiPage\"),\n  },\n];\n\nconst api = (context)=\u003e (props) =\u003e {\n  const msg = useRouteData();\n  const P = styled(\"p\")`color: context.colors.blue[700];`\n  return (\n    \u003cP\u003e\n      Now you can use the data: {msg()}\n    \u003c/P\u003e\n  )\n}\n\nimport context from \"...\"\nexport default function ApiPage() {\n  const Api = api(context)\n  return \u003cApi/\u003e\n}\n\nconst App = () =\u003e {\n  const Routes = useRoutes(routeExample);\n  const { path, data, componenent } = routeExample[0];\n  return (\n    \u003c\u003e\n      \u003cA href={path} data={data} component={componenent}\u003e\n        Go to example\n      \u003c/A\u003e\n      \u003cRoutes /\u003e;\n    \u003c/\u003e\n  )\n}\n\n\nrender(\u003cApp/\u003e,...)\n```\n\n## Pattern for customized functional components with SolidJS\n\nIt uses [Solid Router](https://github.com/solidjs/solid-router) and [Solid styled components](https://github.com/solidjs/solid-styled-components) to produce a fast and very light-weight bundle.\n\nWe don't use `THEMEPROVIDER` via `createContext` but use the pattern below and build custom components such as: `DAILOG`, `MODAL`, `SELECT`, `AUTOCOMPLETE SELECT` with `DATALIST`, `ALERT-STACK`, `DRAWER`, `CHECKBOX`, `BUTTON`, `SPINNERS`...\n\nAn example of how to use `ThemeProvider` is shown [in the docs](https://www.solidjs.com/examples/contex).\n\n## Status\n\nStill building... \u003chttps://solid-components.surge.sh\u003e\n\n## The pattern\n\nYou define a closure that takes an argument - the context - and renders a function component.\n\n```jsx\nconst comp = (context) =\u003e {\n  return (props) =\u003e component(context, props);\n};\n\nconst ContextedComp = comp(someContext);\n\n\u003cContextedComp {...props}\u003e{props.children} \u003c/ContextedComp\u003e;\n```\n\nThis allows to pass a \"static\" theme without using `ThemeProvider` via `createContext`, as described [in the doc \"context\" example](https://www.solidjs.com/examples/context).\n\n:exclamation: **do NOT destructure the props**. See the example below.\n\n## \"Traditional\" CSS file\n\nWe define a component:\n\n```js\nconst TitleV0 = (props) =\u003e \u003ch1 {...props}\u003e{props.children}\u003c/h1\u003e;\n```\n\nWe can use the `style` prop to define in-line CSS and pass a JS object with keys in dash-form with explicit units.\n\n```jsx\n\u003cTitleV0 style={{ color: \"red\", \"font-size\": \"2em\" }}\u003eColor is \"red\"\u003c/TitleV0\u003e\n```\n\nSolidJS provides the prop `class`to pass a CSS class name. Suppose we define CSS classe \"center-blue\" in the file \"index.css\".\n\n```css\n.center-blue {\n  text-align: center;\n  color: blue;\n}\n```\n\nWe import de CSS and can use the CSS classes:\n\n```jsx\n\u003cTitleV0 class=\"center-blue\"\u003eBlue and centered\u003c/TitleV0\u003e\n```\n\n## Using the pattern with CSS-in-JS\n\nWe can use CSS-in-JS with the library [solid-styled-components](https://github.com/solidjs/solid-styled-components).\n\nLets copy-paste CSS into JS and create a \"context\" object:\n\n```js\n// context.js\n\nconst base = `\n  color: red;\n  border: dotted 1px;\n`;\nconst blueSolid = `\n  color: blue;\n  border: solid 1px;\n`;\n\nconst solid = `border: solid 2px;`;\n\nexport default { classes: { base, blueSolid, solid } };\n```\n\nWe can now define customized components that use the `context` object. We use `css` from the package \"solid-styled-components\". We are able to read additional props given to the component.\n\n```js\nimport { css } from \"solid-styled-components\";\n\nconst title = (context) =\u003e (props) =\u003e {\n  const {\n    classes: { base },\n  } = context;\n  const newclass = props.newClass ? base + props.newClass : base;\n  const label = props.label || props.children;\n  return (\n    \u003ch4\n      class={css`\n        ${newclass}\n      `}\n      {...props}\n    \u003e\n      {label}\n    \u003c/h4\u003e\n  );\n};\n```\n\nand use it:\n\n```jsx\nimport context from \"./context.js\";\nconst {classes: {blueSolid, solid}} = context;\n\n[...]\nconst CTitle = title(context);\n\n\u003cCTitle\u003eDefault title is red-dotted\u003c/CTitle\u003e\n\u003cCTitle label=\"Blue solid title\"/\u003e\n\u003cCTitle newClass={solid}\u003eBlue solid\u003c/CTitle\u003e\n```\n\nWe can also use `styled`from \"solid-styled-components\" if we only want to change the CSS. This returns a styled function component.\n\nWe can use classes (a CSS class, not transformed by `css`):)\n\n```jsx\nimport { styled } from \"solid-styled-components\";\n\nconst sTitle = (context) =\u003e\n  (tag, base) =\u003e\n    styled(tag)((props) =\u003e {\n      return props.newClass ? base + props.newClass : base;\n    });\n\nconst H1 = sTitle(context)(\"h1\");\n\u003cH1\u003e A red dotted h1\u003c/H1\u003e\n\u003cH1 newClass={blueSolid}\u003eBlue solid h1\u003c/H1\u003e\n```\n\nWe can also define:\n\n```jsx\nconst dynTitle = (tag, css, optCss = \"\") =\u003e\n  style(tag)`\n  ${css}\n  ${optCss}\n`;\n```\n\nand use it:\n\n```jsx\nconst DTitle = dynTitle(\"h5\", base, blueSolid);\n```\n\n## Context\n\nThe \"context\" object here is (based on Material UI colors and HTML color codes):\n\n```js\nimport { red, orange, teal, blue, grey } from \"material-ui-colors\";\n```\n\nWhen we see that we use frequently a CSS classe, we add it to the context, and the other local CSS class definitions can be defined locally in the componenent.\n\n```js\ncontext.classes.stdTitle = `\n  border: none; \n  text-align: left;\n  color: #0D2E46;\n  padding-left: 12px;\n  background-color: ${context.theme.bg.bisque};\n  color: ${grey[800]};\n  box-shadow: ${context.shadows[2]};\n  `;\n```\n\n## Note on mobile\n\nView on mobile (within the same WIFI): build it, server it, open it.\n\n```bash\nnpm run build\nhttp-server ./dist -b 0.0.0.0 -p 8080\n```\n\nand navigate with the mobile to \u003chttp://127.0.0.1:8080\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fndrean%2Fsolid-components","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fndrean%2Fsolid-components","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fndrean%2Fsolid-components/lists"}