{"id":26417407,"url":"https://github.com/maybebot/named-slots","last_synced_at":"2026-01-23T05:54:33.125Z","repository":{"id":280578529,"uuid":"942233652","full_name":"maybebot/named-slots","owner":"maybebot","description":"Named slots for preact","archived":false,"fork":false,"pushed_at":"2025-10-26T20:07:03.000Z","size":148,"stargazers_count":6,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-26T21:13:41.384Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/maybebot.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-03-03T19:37:39.000Z","updated_at":"2025-10-26T19:20:50.000Z","dependencies_parsed_at":"2025-04-16T09:49:27.423Z","dependency_job_id":null,"html_url":"https://github.com/maybebot/named-slots","commit_stats":null,"previous_names":["maybebot/named-slots"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/maybebot/named-slots","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maybebot%2Fnamed-slots","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maybebot%2Fnamed-slots/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maybebot%2Fnamed-slots/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maybebot%2Fnamed-slots/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maybebot","download_url":"https://codeload.github.com/maybebot/named-slots/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maybebot%2Fnamed-slots/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28681502,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T05:48:07.525Z","status":"ssl_error","status_checked_at":"2026-01-23T05:48:07.129Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":[],"created_at":"2025-03-18T01:01:53.262Z","updated_at":"2026-01-23T05:54:33.114Z","avatar_url":"https://github.com/maybebot.png","language":"TypeScript","readme":"# named-slots\n\nSlots for preact, react and solid in under 0.2Kb.\n\nSlots allow to define \"holes\" in your components that can be filled with JSX.\nInspired by slots in Vue/Svelte/Angular/WebComponents.\n\n\u003cimg align=\"right\" width=\"50\" height=\"50\" src=\"https://github.com/maybebot/named-slots/blob/main/frameworks/solid/solid.svg\"\u003e\n\u003cimg align=\"right\" width=\"50\" height=\"50\" src=\"https://github.com/maybebot/named-slots/blob/main/frameworks/react/react.svg\"\u003e\n\u003cimg align=\"right\" width=\"50\" height=\"50\" src=\"https://github.com/maybebot/named-slots/blob/main/frameworks/preact/preact.svg\"\u003e\n\n```sh\nnpm i named-slots\n```\n\n## Quick start\n\n### Defining slots\n\nSet the names of the slots you're using with `defineSlots` and use them in your JSX like `\u003cSlot name=\"slotName\"\u003e`, where want the slotted content to appear.\n\n```tsx\nimport { defineSlots } from \"named-slots\";\n\nexport const Card = ({ children }) =\u003e {\n  const { Slot } = defineSlots(children, [\"header\", \"content\", \"footer\"]);\n\n  return (\n    \u003cdiv className=\"card\"\u003e\n      \u003cSlot name=\"header\"\u003e\u003c/Slot\u003e\n      \u003cSlot name=\"content\"\u003e\n        \u003cdiv\u003eFallback content\u003c/div\u003e\n      \u003c/Slot\u003e\n      \u003cdiv\u003e\n        \u003cSlot name=\"footer\"\u003eFallback footer\u003c/Slot\u003e\n      \u003c/div\u003e\n    \u003c/div\u003e\n  );\n};\n```\n\n### Consuming components with Slots\n\nNow you can slot content into your Card component. The only thing you need to do is set a `slot=\"slotName\"` on the element you wish to slot in. To render only text or multiple elements, use the `\u003ctemplate\u003e` element.\n\n```tsx\n\u003cCard\u003e\n  \u003cdiv slot=\"header\"\u003eThis div is not semantic\u003c/div\u003e\n  \u003cRandomComponent slot=\"content\" /\u003e\n  \u003ctemplate slot=\"footer\"\u003e\n    \u003cdiv\u003eOne\u003c/div\u003e\n    \u003cdiv\u003eTwo\u003c/div\u003e\n  \u003c/template\u003e\n\u003c/Card\u003e\n```\n\n## Fallback\n\nWhen defining a `\u003cSlot\u003e` the content inside of it will be treated as fallback, in case nothing is slotted inside of that slot. If you do not want anything to be rendered, self-close the slot tag `\u003cSlot name=\"nofallback\" /\u003e`.\n\n```\n\u003cActionBar\u003e\n  \u003cSlot name=\"left\" /\u003e {/* no fallback, will not render unless slotted*/}\n  \u003cSlot name=\"right\"\u003eLoading...\u003c/Slot\u003e {/* Will render \"Loading...\" until slotted */}\n\u003c/ActionBar\u003e\n```\n\n## defineSlots and hasSlot\n\nThe `defineSlots` function handles the usage of slots. It takes the `children` prop of the component where it's used, and a string array of the slot names. If using Typescript add a `as const` to the string array so Typescript can check if the slot names are typed correctly.\n\n`defineSlots` returns an object with the `Slot` component, but also a `hasSlot` function that allows to check if a slot has been slotted in, for conditional rendering.\n\n```tsx\nexport const DefinedCard = ({ children }: { children: Slottable }) =\u003e {\n  const { Slot, hasSlot } = defineSlots(children, [\"header\", \"content\", \"footer\"] as const);\n\n  const hasContent: boolean = hasSlot(\"content\");\n```\n\n## With Solid.js\n\nSince solid does not use a VDOM it has a dedicated import.\n\n```ts\nimport { Slot } from \"named-slots/solid\";\n```\n\nIn addition every element with `slot` needs to be an HTML element, not a Solid component (or wrapped in one like the `\u003ctemplate\u003e`). In the example above, `\u003cRandomComponent slot=\"content\" /\u003e` would not work. `\u003cdiv =\"content\"\u003e\u003cRandomComponent slot=\"content\" /\u003e\u003c/div\u003e` would.\n\n---\n\nMade with 🍕 in Amsterdam.\n","funding_links":[],"categories":["Angular-Inspired Solutions"],"sub_categories":["Wrappers"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaybebot%2Fnamed-slots","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaybebot%2Fnamed-slots","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaybebot%2Fnamed-slots/lists"}