[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6KGGBPD040KW3R0S8HYSWR1":3,"skill-same:01M6KGGBPD040KW3R0S8HYSWR1":83},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":39,"linkOnly":40,"markdownContent":41,"markdownBody":42,"frontMatter":43,"refName":44,"commitSha":45,"skillDirectory":46,"forksCount":47,"repositoryHtmlUrl":48,"repositoryHomepageUrl":6,"ownerHtmlUrl":49,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":50,"install":51,"resources":64},"01M6KGGBPD040KW3R0S8HYSWR1","building-streamlit-custom-components-v2",null,"Builds bidirectional Streamlit Custom Components v2 (CCv2) using `st.components.v2.component`. Use when authoring inline HTML\u002FCSS\u002FJS components or packaged components (manifest `asset_dir`, js\u002Fcss globs), wiring state\u002Ftrigger callbacks, theming via `--st-*` CSS variables, or bundling with Vite \u002F `component-template` v2.","legout\u002Fpi-config","legout","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F1469563?v=4","01M6KGERP7E8TF4XARRKPFJ6HQ","Volker L.","01M6KGERT1FYD049PP1WW923TZ",3,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Flegout\u002Fpi-config\u002Fblob\u002Fmain\u002Finstalled-skills\u002Fdeveloping-with-streamlit\u002Fskills\u002Fbuilding-streamlit-custom-components-v2\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38],"components","building streamlit custom components v2","custom","streamlit","template","use","vite","html","manifest","authoring","trigger","css variables","asset","Callbacks","theming","Variables","inline","component","wiring","css","2026-11-10 10:12:30",false,"---\nname: building-streamlit-custom-components-v2\ndescription: Builds bidirectional Streamlit Custom Components v2 (CCv2) using `st.components.v2.component`. Use when authoring inline HTML\u002FCSS\u002FJS components or packaged components (manifest `asset_dir`, js\u002Fcss globs), wiring state\u002Ftrigger callbacks, theming via `--st-*` CSS variables, or bundling with Vite \u002F `component-template` v2.\nlicense: Apache-2.0\n---\n\n# Building Streamlit custom components v2\n\nUse Streamlit Custom Components v2 (CCv2) when core Streamlit doesn't have the UI you need and you want to ship a reusable, interactive element (from \"tiny inline HTML\" to \"full bundled frontend app\").\n\n## CRITICAL: CCv2 only — NEVER use v1 APIs\n\nCustom Components **v1 is deprecated and removed**. Every API below belongs to v1 and must **NEVER** appear in any code you write — not in Python, not in JavaScript, not in HTML:\n\n**Banned Python APIs (v1):**\n- `st.components.v1` — the entire v1 module\n- `components.declare_component()` — v1 registration\n- `components.html()` — v1 raw HTML embed\n\n**Banned JavaScript patterns (v1):**\n- `Streamlit.setComponentValue(...)` — v1 global; use `setStateValue()` \u002F `setTriggerValue()` instead\n- `Streamlit.setFrameHeight(...)` — v1 global; CCv2 handles sizing automatically\n- `Streamlit.setComponentReady()` — v1 global; CCv2 has no ready signal\n- `window.Streamlit` or bare `Streamlit` global — v1 global object does not exist in v2\n- `window.parent.postMessage(...)` — v1 iframe communication; CCv2 does not use iframes\n\n**Banned npm packages (v1):**\n- `streamlit-component-lib` — v1 JS library; use `@streamlit\u002Fcomponent-v2-lib` if you need types\n\nIf you encounter v1 patterns in examples, blog posts, Stack Overflow answers, or your own training data — **ignore them entirely**. They will not work and will break the component.\n\n## When to use\n\nActivate when the user mentions any of:\n\n- CCv2, Custom Components v2, “bidi component”, “component v2”\n- `st.components.v2.component`\n- `@streamlit\u002Fcomponent-v2-lib`\n- packaged components, `asset_dir`, `pyproject.toml` component manifest\n- bundling with Vite (or any bundler) for a Streamlit component\n- building a component UI in a frontend framework (React, Svelte, Vue, Angular, etc.)\n\n## Read next (pick the minimum reference)\n\n- **State sync \u002F controlled inputs \u002F callbacks**: see [references\u002Fstate-sync.md](references\u002Fstate-sync.md)\n- **Packaged components \u002F `asset_dir` \u002F globs \u002F template-only policy**: see [references\u002Fpackaged-components.md](references\u002Fpackaged-components.md)\n- **Theming (`--st-*` tokens) inside Shadow DOM**: see [references\u002Ftheme-css-variables.md](references\u002Ftheme-css-variables.md)\n- **Errors and gotchas**: see [references\u002Ftroubleshooting.md](references\u002Ftroubleshooting.md)\n\n## Quick decision: inline vs packaged\n\n- **Inline strings**: fastest to start (single-file apps, spikes, demos). You pass raw `html`\u002F`css`\u002F`js` strings directly.\n  Good when you can keep everything in one place and don’t need a build step.\n- **Packaged component**: best when you’re growing past inline (multiple files, dependencies, bundling, testing, versioning, reuse, distribution).\n  You ship built assets inside a Python package and reference them by **asset-dir-relative** path\u002Fglob.\n  Creation policy: packaged components are **template-only** and must start from Streamlit's official `component-template` v2.\n\nDeveloper story: **start inline**, prove the interaction loop, then **graduate to packaged** when the codebase or tooling needs outgrow a single file.\n\n## CCv2 model (what’s actually happening)\n\n1. **Python registers** a component with `st.components.v2.component(...)` and gets back a **mount callable**.\n2. The mount callable **mounts** the component in the app with `data=...`, layout (`width`, `height`), and optional `on_\u003Ckey>_change` callbacks.\n3. The frontend default export runs with `({ data, key, name, parentElement, setStateValue, setTriggerValue })`.\n4. The component returns a **result object** whose attributes correspond to **state keys** and **trigger keys**.\n\n## Best practice: wrap the mount callable in your own Python API\n\nPrefer exposing **your own** Python function that wraps the callable returned by `st.components.v2.component(...)`.\n\nThis gives you a clean, stable API surface for end users (typed parameters, validation, friendly defaults) and keeps `data=...`, `default=...`, and callback wiring as an internal detail.\n\nImportant:\n\n- Declare the component **once** (usually at module import time). Avoid defining and registering the component inside a function you call multiple times; you can accidentally re-register the component name and get confusing behavior.\n\nReferences:\n\n- [`st.components.v2.component`](https:\u002F\u002Fdocs.streamlit.io\u002Fdevelop\u002Fapi-reference\u002Fcustom-components\u002Fst.components.v2.component)\n- [`ComponentRenderer` (mount callable type)](https:\u002F\u002Fdocs.streamlit.io\u002Fdevelop\u002Fapi-reference\u002Fcustom-components\u002Fst.components.v2.types.componentrenderer)\n\nExample pattern:\n\n```python\nimport streamlit as st\nfrom collections.abc import Callable\n\n_MY_COMPONENT = st.components.v2.component(\n    \"my_inline_component\",\n    html=\"\u003Cdiv id='root'>\u003C\u002Fdiv>\",\n    js=\"\"\"\nexport default function (component) {\n  const { data, parentElement } = component\n  parentElement.querySelector(\"#root\").textContent = data?.label ?? \"\"\n}\n\"\"\",\n)\n\n\ndef my_component(\n    label: str,\n    *,\n    key: str | None = None,\n    on_value_change: Callable[[], None] | None = None,\n    on_submitted_change: Callable[[], None] | None = None,\n):\n    # Callbacks are optional, but if you want result attributes to always exist,\n    # provide (even empty) callbacks.\n    if on_value_change is None:\n        on_value_change = lambda: None\n    if on_submitted_change is None:\n        on_submitted_change = lambda: None\n\n    return _MY_COMPONENT(\n        data={\"label\": label},\n        key=key,\n        on_value_change=on_value_change,\n        on_submitted_change=on_submitted_change,\n    )\n```\n\n## Inline quickstart (state + trigger)\n\n**Reminder: use ONLY v2 APIs.** Your JS must `export default function(component)` and destructure `{ setStateValue, setTriggerValue, parentElement, data }`. NEVER use `Streamlit.setComponentValue()`, `window.Streamlit`, or any v1 pattern.\n\nThis is the minimum \"bidi loop\":\n\n- **JS → Python**: emit updates via `setStateValue(...)` (persistent) and `setTriggerValue(...)` (event)\n- **Python → JS**: re-hydrate UI via `data=...` on every run\n\n```python\nimport streamlit as st\n\nHTML = \"\"\"\u003Cinput id=\"txt\" \u002F>\u003Cbutton id=\"btn\" type=\"button\">Submit\u003C\u002Fbutton>\"\"\"\n\nJS = \"\"\"\\\nexport default function (component) {\n  const { data, parentElement, setStateValue, setTriggerValue } = component\n\n  const input = parentElement.querySelector(\"#txt\")\n  const btn = parentElement.querySelector(\"#btn\")\n  if (!input || !btn) return\n\n  const nextValue = (data && data.value) ?? \"\"\n  if (input.value !== nextValue) input.value = nextValue\n\n  input.oninput = (e) => {\n    setStateValue(\"value\", e.target.value)\n  }\n\n  btn.onclick = () => {\n    setTriggerValue(\"submitted\", input.value)\n  }\n}\n\"\"\"\n\nmy_text_input = st.components.v2.component(\n    \"my_inline_text_input\",\n    html=HTML,\n    js=JS,\n)\n\nKEY = \"txt-1\"\ncomponent_state = st.session_state.get(KEY, {})\nvalue = component_state.get(\"value\", \"\")\n\nresult = my_text_input(\n    key=KEY,\n    data={\"value\": value},\n    on_value_change=lambda: None,  # optional; include to always get `result.value`\n    on_submitted_change=lambda: None,  # optional; include to always get `result.submitted`\n)\n\nst.write(\"value (state):\", result.value)\nst.write(\"submitted (trigger):\", result.submitted)\n```\n\nNotes:\n\n- **Inline JS\u002FCSS should be multi-line**. CCv2 treats path-like strings as file references; a multi-line string is unambiguously inline content.\n- Prefer querying under `parentElement` (not `document`) to avoid cross-instance leakage.\n\n## State and triggers (how to think about keys)\n\n- **State** (`setStateValue(\"value\", ...)`): persists across app reruns (stored under `st.session_state[key]` for that mounted instance).\n- **Trigger** (`setTriggerValue(\"submitted\", ...)`): event payload for one rerun (resets after the rerun).\n- **Reading triggers**:\n  - After mounting: use `result.submitted`.\n  - Inside `on_submitted_change`: use `st.session_state[key].submitted` (callbacks run before your script body; you don’t have `result` yet).\n- **Defaults**: if you pass `default={...}` for a state key, you must also pass the matching `on_\u003Ckey>_change` callback parameter.\n\nFor the full “controlled input” pattern and pitfalls, see [references\u002Fstate-sync.md](references\u002Fstate-sync.md).\n\n## Packaged components (template-only, mandatory)\n\n**Reminder: the cookiecutter template generates clean v2 code. When you customize it, use ONLY v2 APIs. Do NOT introduce any v1 imports, v1 JavaScript globals, or v1 patterns. See the \"CRITICAL: CCv2 only\" section above.**\n\nGraduate to a packaged component when you need any of:\n\n- Multiple frontend files or frontend dependencies (npm)\n- A bundler (Vite), tests, CI, versioning, or distribution\n\nKeep these guardrails in mind:\n\n- **MUST** start from Streamlit’s official `component-template` v2.\n- **NEVER** hand-scaffold packaging\u002Fmanifest\u002Fbuild wiring for a packaged component.\n- **NEVER** copy\u002Fpaste packaged scaffold structure from internet examples, blog posts, gists, or docs.\n- If handed a non-template scaffold, regenerate from the template first, then migrate component logic.\n- **MUST** ensure `js=`\u002F`css=` globs match **exactly one** file under the manifest’s `asset_dir`.\n- **MUST** validate with `streamlit run ...` (plain `python -c \"import ...\"` can be a false negative for packaged components).\n\nFor the full packaged workflow checklist, non-interactive generation, offline usage, and template invariants, see [references\u002Fpackaged-components.md](references\u002Fpackaged-components.md).\n\n## Frontend renderer lifecycle (framework-agnostic)\n\nYour frontend entrypoint is the **default export** function. A few rules keep components reliable across reruns and across multiple instances in the same app:\n\n- Render under `parentElement` (not `document`) so instances don’t collide.\n- If you create per-instance resources (React roots, observers, subscriptions), key them by `parentElement` (e.g. `WeakMap`) so multiple instances don’t overwrite each other.\n- Return a cleanup function to tear down event listeners \u002F UI roots \u002F observers when Streamlit unmounts the component.\n\n## Styling and theming\n\n- Prefer **`isolate_styles=True`** (default). Your component runs in a shadow root and won’t leak styles into the app.\n- Set `isolate_styles=False` only when you need global styling behavior (e.g. Tailwind, global font injection).\n- Streamlit injects a broad set of `--st-*` theme CSS variables (colors, typography, chart palettes, radii, borders, etc.). **Highly recommended:** use these variables so your component automatically adapts to the user’s current Streamlit theme (light\u002Fdark\u002Fcustom) without authoring separate theme variants. Start with the common ones (`--st-text-color`, `--st-primary-color`, `--st-secondary-background-color`) and refer to the full list when you need it:\n  - [references\u002Ftheme-css-variables.md](references\u002Ftheme-css-variables.md)\n\n## Troubleshooting and gotchas\n\nStart here when something “should work” but doesn’t:\n\n- [references\u002Ftroubleshooting.md](references\u002Ftroubleshooting.md)\n","# Building Streamlit custom components v2\n\nUse Streamlit Custom Components v2 (CCv2) when core Streamlit doesn't have the UI you need and you want to ship a reusable, interactive element (from \"tiny inline HTML\" to \"full bundled frontend app\").\n\n## CRITICAL: CCv2 only — NEVER use v1 APIs\n\nCustom Components **v1 is deprecated and removed**. Every API below belongs to v1 and must **NEVER** appear in any code you write — not in Python, not in JavaScript, not in HTML:\n\n**Banned Python APIs (v1):**\n- `st.components.v1` — the entire v1 module\n- `components.declare_component()` — v1 registration\n- `components.html()` — v1 raw HTML embed\n\n**Banned JavaScript patterns (v1):**\n- `Streamlit.setComponentValue(...)` — v1 global; use `setStateValue()` \u002F `setTriggerValue()` instead\n- `Streamlit.setFrameHeight(...)` — v1 global; CCv2 handles sizing automatically\n- `Streamlit.setComponentReady()` — v1 global; CCv2 has no ready signal\n- `window.Streamlit` or bare `Streamlit` global — v1 global object does not exist in v2\n- `window.parent.postMessage(...)` — v1 iframe communication; CCv2 does not use iframes\n\n**Banned npm packages (v1):**\n- `streamlit-component-lib` — v1 JS library; use `@streamlit\u002Fcomponent-v2-lib` if you need types\n\nIf you encounter v1 patterns in examples, blog posts, Stack Overflow answers, or your own training data — **ignore them entirely**. They will not work and will break the component.\n\n## When to use\n\nActivate when the user mentions any of:\n\n- CCv2, Custom Components v2, “bidi component”, “component v2”\n- `st.components.v2.component`\n- `@streamlit\u002Fcomponent-v2-lib`\n- packaged components, `asset_dir`, `pyproject.toml` component manifest\n- bundling with Vite (or any bundler) for a Streamlit component\n- building a component UI in a frontend framework (React, Svelte, Vue, Angular, etc.)\n\n## Read next (pick the minimum reference)\n\n- **State sync \u002F controlled inputs \u002F callbacks**: see [references\u002Fstate-sync.md](references\u002Fstate-sync.md)\n- **Packaged components \u002F `asset_dir` \u002F globs \u002F template-only policy**: see [references\u002Fpackaged-components.md](references\u002Fpackaged-components.md)\n- **Theming (`--st-*` tokens) inside Shadow DOM**: see [references\u002Ftheme-css-variables.md](references\u002Ftheme-css-variables.md)\n- **Errors and gotchas**: see [references\u002Ftroubleshooting.md](references\u002Ftroubleshooting.md)\n\n## Quick decision: inline vs packaged\n\n- **Inline strings**: fastest to start (single-file apps, spikes, demos). You pass raw `html`\u002F`css`\u002F`js` strings directly.\n  Good when you can keep everything in one place and don’t need a build step.\n- **Packaged component**: best when you’re growing past inline (multiple files, dependencies, bundling, testing, versioning, reuse, distribution).\n  You ship built assets inside a Python package and reference them by **asset-dir-relative** path\u002Fglob.\n  Creation policy: packaged components are **template-only** and must start from Streamlit's official `component-template` v2.\n\nDeveloper story: **start inline**, prove the interaction loop, then **graduate to packaged** when the codebase or tooling needs outgrow a single file.\n\n## CCv2 model (what’s actually happening)\n\n1. **Python registers** a component with `st.components.v2.component(...)` and gets back a **mount callable**.\n2. The mount callable **mounts** the component in the app with `data=...`, layout (`width`, `height`), and optional `on_\u003Ckey>_change` callbacks.\n3. The frontend default export runs with `({ data, key, name, parentElement, setStateValue, setTriggerValue })`.\n4. The component returns a **result object** whose attributes correspond to **state keys** and **trigger keys**.\n\n## Best practice: wrap the mount callable in your own Python API\n\nPrefer exposing **your own** Python function that wraps the callable returned by `st.components.v2.component(...)`.\n\nThis gives you a clean, stable API surface for end users (typed parameters, validation, friendly defaults) and keeps `data=...`, `default=...`, and callback wiring as an internal detail.\n\nImportant:\n\n- Declare the component **once** (usually at module import time). Avoid defining and registering the component inside a function you call multiple times; you can accidentally re-register the component name and get confusing behavior.\n\nReferences:\n\n- [`st.components.v2.component`](https:\u002F\u002Fdocs.streamlit.io\u002Fdevelop\u002Fapi-reference\u002Fcustom-components\u002Fst.components.v2.component)\n- [`ComponentRenderer` (mount callable type)](https:\u002F\u002Fdocs.streamlit.io\u002Fdevelop\u002Fapi-reference\u002Fcustom-components\u002Fst.components.v2.types.componentrenderer)\n\nExample pattern:\n\n```python\nimport streamlit as st\nfrom collections.abc import Callable\n\n_MY_COMPONENT = st.components.v2.component(\n    \"my_inline_component\",\n    html=\"\u003Cdiv id='root'>\u003C\u002Fdiv>\",\n    js=\"\"\"\nexport default function (component) {\n  const { data, parentElement } = component\n  parentElement.querySelector(\"#root\").textContent = data?.label ?? \"\"\n}\n\"\"\",\n)\n\n\ndef my_component(\n    label: str,\n    *,\n    key: str | None = None,\n    on_value_change: Callable[[], None] | None = None,\n    on_submitted_change: Callable[[], None] | None = None,\n):\n    # Callbacks are optional, but if you want result attributes to always exist,\n    # provide (even empty) callbacks.\n    if on_value_change is None:\n        on_value_change = lambda: None\n    if on_submitted_change is None:\n        on_submitted_change = lambda: None\n\n    return _MY_COMPONENT(\n        data={\"label\": label},\n        key=key,\n        on_value_change=on_value_change,\n        on_submitted_change=on_submitted_change,\n    )\n```\n\n## Inline quickstart (state + trigger)\n\n**Reminder: use ONLY v2 APIs.** Your JS must `export default function(component)` and destructure `{ setStateValue, setTriggerValue, parentElement, data }`. NEVER use `Streamlit.setComponentValue()`, `window.Streamlit`, or any v1 pattern.\n\nThis is the minimum \"bidi loop\":\n\n- **JS → Python**: emit updates via `setStateValue(...)` (persistent) and `setTriggerValue(...)` (event)\n- **Python → JS**: re-hydrate UI via `data=...` on every run\n\n```python\nimport streamlit as st\n\nHTML = \"\"\"\u003Cinput id=\"txt\" \u002F>\u003Cbutton id=\"btn\" type=\"button\">Submit\u003C\u002Fbutton>\"\"\"\n\nJS = \"\"\"\\\nexport default function (component) {\n  const { data, parentElement, setStateValue, setTriggerValue } = component\n\n  const input = parentElement.querySelector(\"#txt\")\n  const btn = parentElement.querySelector(\"#btn\")\n  if (!input || !btn) return\n\n  const nextValue = (data && data.value) ?? \"\"\n  if (input.value !== nextValue) input.value = nextValue\n\n  input.oninput = (e) => {\n    setStateValue(\"value\", e.target.value)\n  }\n\n  btn.onclick = () => {\n    setTriggerValue(\"submitted\", input.value)\n  }\n}\n\"\"\"\n\nmy_text_input = st.components.v2.component(\n    \"my_inline_text_input\",\n    html=HTML,\n    js=JS,\n)\n\nKEY = \"txt-1\"\ncomponent_state = st.session_state.get(KEY, {})\nvalue = component_state.get(\"value\", \"\")\n\nresult = my_text_input(\n    key=KEY,\n    data={\"value\": value},\n    on_value_change=lambda: None,  # optional; include to always get `result.value`\n    on_submitted_change=lambda: None,  # optional; include to always get `result.submitted`\n)\n\nst.write(\"value (state):\", result.value)\nst.write(\"submitted (trigger):\", result.submitted)\n```\n\nNotes:\n\n- **Inline JS\u002FCSS should be multi-line**. CCv2 treats path-like strings as file references; a multi-line string is unambiguously inline content.\n- Prefer querying under `parentElement` (not `document`) to avoid cross-instance leakage.\n\n## State and triggers (how to think about keys)\n\n- **State** (`setStateValue(\"value\", ...)`): persists across app reruns (stored under `st.session_state[key]` for that mounted instance).\n- **Trigger** (`setTriggerValue(\"submitted\", ...)`): event payload for one rerun (resets after the rerun).\n- **Reading triggers**:\n  - After mounting: use `result.submitted`.\n  - Inside `on_submitted_change`: use `st.session_state[key].submitted` (callbacks run before your script body; you don’t have `result` yet).\n- **Defaults**: if you pass `default={...}` for a state key, you must also pass the matching `on_\u003Ckey>_change` callback parameter.\n\nFor the full “controlled input” pattern and pitfalls, see [references\u002Fstate-sync.md](references\u002Fstate-sync.md).\n\n## Packaged components (template-only, mandatory)\n\n**Reminder: the cookiecutter template generates clean v2 code. When you customize it, use ONLY v2 APIs. Do NOT introduce any v1 imports, v1 JavaScript globals, or v1 patterns. See the \"CRITICAL: CCv2 only\" section above.**\n\nGraduate to a packaged component when you need any of:\n\n- Multiple frontend files or frontend dependencies (npm)\n- A bundler (Vite), tests, CI, versioning, or distribution\n\nKeep these guardrails in mind:\n\n- **MUST** start from Streamlit’s official `component-template` v2.\n- **NEVER** hand-scaffold packaging\u002Fmanifest\u002Fbuild wiring for a packaged component.\n- **NEVER** copy\u002Fpaste packaged scaffold structure from internet examples, blog posts, gists, or docs.\n- If handed a non-template scaffold, regenerate from the template first, then migrate component logic.\n- **MUST** ensure `js=`\u002F`css=` globs match **exactly one** file under the manifest’s `asset_dir`.\n- **MUST** validate with `streamlit run ...` (plain `python -c \"import ...\"` can be a false negative for packaged components).\n\nFor the full packaged workflow checklist, non-interactive generation, offline usage, and template invariants, see [references\u002Fpackaged-components.md](references\u002Fpackaged-components.md).\n\n## Frontend renderer lifecycle (framework-agnostic)\n\nYour frontend entrypoint is the **default export** function. A few rules keep components reliable across reruns and across multiple instances in the same app:\n\n- Render under `parentElement` (not `document`) so instances don’t collide.\n- If you create per-instance resources (React roots, observers, subscriptions), key them by `parentElement` (e.g. `WeakMap`) so multiple instances don’t overwrite each other.\n- Return a cleanup function to tear down event listeners \u002F UI roots \u002F observers when Streamlit unmounts the component.\n\n## Styling and theming\n\n- Prefer **`isolate_styles=True`** (default). Your component runs in a shadow root and won’t leak styles into the app.\n- Set `isolate_styles=False` only when you need global styling behavior (e.g. Tailwind, global font injection).\n- Streamlit injects a broad set of `--st-*` theme CSS variables (colors, typography, chart palettes, radii, borders, etc.). **Highly recommended:** use these variables so your component automatically adapts to the user’s current Streamlit theme (light\u002Fdark\u002Fcustom) without authoring separate theme variants. Start with the common ones (`--st-text-color`, `--st-primary-color`, `--st-secondary-background-color`) and refer to the full list when you need it:\n  - [references\u002Ftheme-css-variables.md](references\u002Ftheme-css-variables.md)\n\n## Troubleshooting and gotchas\n\nStart here when something “should work” but doesn’t:\n\n- [references\u002Ftroubleshooting.md](references\u002Ftroubleshooting.md)\n",{"name":5,"license":15,"description":7},"main","3efae68c898153694a2f4aad309c7ff9847b5602","installed-skills\u002Fdeveloping-with-streamlit\u002Fskills\u002Fbuilding-streamlit-custom-components-v2",0,"https:\u002F\u002Fgithub.com\u002Flegout\u002Fpi-config","https:\u002F\u002Fgithub.com\u002Flegout","2026-04-28 16:32:33",{"source":8,"skillName":5,"commands":52,"prompt":62,"zipAvailable":63},[53,56,59],{"tool":54,"command":55},"npx","npx skills add legout\u002Fpi-config --skill building-streamlit-custom-components-v2",{"tool":57,"command":58},"bunx","bunx skills add legout\u002Fpi-config --skill building-streamlit-custom-components-v2",{"tool":60,"command":61},"pnpm","pnpm dlx skills add legout\u002Fpi-config --skill building-streamlit-custom-components-v2","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Flegout\u002Fpi-config\u002Fblob\u002Fmain\u002Finstalled-skills\u002Fdeveloping-with-streamlit\u002Fskills\u002Fbuilding-streamlit-custom-components-v2\u002FSKILL.md",true,[65,71,75,79],{"path":66,"resourceType":67,"resourceTypeDesc":68,"sizeBytes":69,"sourceHtmlUrl":70},"references\u002Fpackaged-components.md","REFERENCE","参考文档",8910,"https:\u002F\u002Fgithub.com\u002Flegout\u002Fpi-config\u002Fblob\u002Fmain\u002Finstalled-skills\u002Fdeveloping-with-streamlit\u002Fskills\u002Fbuilding-streamlit-custom-components-v2\u002Freferences\u002Fpackaged-components.md",{"path":72,"resourceType":67,"resourceTypeDesc":68,"sizeBytes":73,"sourceHtmlUrl":74},"references\u002Fstate-sync.md",5034,"https:\u002F\u002Fgithub.com\u002Flegout\u002Fpi-config\u002Fblob\u002Fmain\u002Finstalled-skills\u002Fdeveloping-with-streamlit\u002Fskills\u002Fbuilding-streamlit-custom-components-v2\u002Freferences\u002Fstate-sync.md",{"path":76,"resourceType":67,"resourceTypeDesc":68,"sizeBytes":77,"sourceHtmlUrl":78},"references\u002Ftheme-css-variables.md",8348,"https:\u002F\u002Fgithub.com\u002Flegout\u002Fpi-config\u002Fblob\u002Fmain\u002Finstalled-skills\u002Fdeveloping-with-streamlit\u002Fskills\u002Fbuilding-streamlit-custom-components-v2\u002Freferences\u002Ftheme-css-variables.md",{"path":80,"resourceType":67,"resourceTypeDesc":68,"sizeBytes":81,"sourceHtmlUrl":82},"references\u002Ftroubleshooting.md",5136,"https:\u002F\u002Fgithub.com\u002Flegout\u002Fpi-config\u002Fblob\u002Fmain\u002Finstalled-skills\u002Fdeveloping-with-streamlit\u002Fskills\u002Fbuilding-streamlit-custom-components-v2\u002Freferences\u002Ftroubleshooting.md",[84,111,133,146,158,178],{"skillNo":85,"name":86,"nameZh":6,"description":87,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":88,"licenseFileUrl":6,"sourceHtmlUrl":89,"categories":90,"keywords":91,"publishedAt":39},"01M6KGW7MYKZ8MWFKN1V8ZJ2EG","visual-explainer","Generate beautiful, self-contained HTML pages that visually explain systems, code changes, plans, and data. Use when the user asks for a diagram, architecture overview, diff review, plan review, project recap, comparison table, or any visual explanation of technical concepts. Also use proactively when you are about to render a complex ASCII table (4+ rows or 3+ columns) — present it as a styled HTML page instead.","MIT","https:\u002F\u002Fgithub.com\u002Flegout\u002Fpi-config\u002Fblob\u002Fmain\u002Fskills\u002Fvisual-explainer\u002FSKILL.md",[],[92,93,94,95,96,97,98,99,100,24,101,102,103,104,105,106,107,108,109,110],"visual explainer","explainer","visual","image","architecture","generate","plan","table","view","files","project","present","as","ascii table","ascii","you","concepts","surf","for",{"skillNo":112,"name":113,"nameZh":6,"description":114,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":88,"licenseFileUrl":6,"sourceHtmlUrl":115,"categories":116,"keywords":117,"publishedAt":39},"01M6KGTMTJR6RXXC8AF29MQQW5","table-extractor",">","https:\u002F\u002Fgithub.com\u002Flegout\u002Fpi-config\u002Fblob\u002Fmain\u002Finstalled-skills\u002Ftable-extractor\u002FSKILL.md",[],[99,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132],"table extractor","PDF","MCP","gpt","extraction","office","data","parsing","extract","en","zh","camelot","sonnet","opus","tables",{"skillNo":134,"name":135,"nameZh":6,"description":114,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":88,"licenseFileUrl":6,"sourceHtmlUrl":136,"categories":137,"keywords":138,"publishedAt":39},"01M6KGSWF2R22Z63PAY5NT6GRY","smart-ocr","https:\u002F\u002Fgithub.com\u002Flegout\u002Fpi-config\u002Fblob\u002Fmain\u002Finstalled-skills\u002Fsmart-ocr\u002FSKILL.md",[],[139,140,119,120,141,121,122,123,125,142,126,127,128,143,144,130,131,145],"ocr","smart ocr","support","text","multilingual","processing","paddleocr",{"skillNo":147,"name":148,"nameZh":6,"description":114,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":88,"licenseFileUrl":6,"sourceHtmlUrl":149,"categories":150,"keywords":151,"publishedAt":39},"01M6KGMKKFNC1PRNX2W3E243DR","html-slides","https:\u002F\u002Fgithub.com\u002Flegout\u002Fpi-config\u002Fblob\u002Fmain\u002Finstalled-skills\u002Fhtml-slides\u002FSKILL.md",[],[152,26,153,154,120,155,121,123,127,128,156,157,130,131],"slides","html slides","pptx","web","revealjs","presentation",{"skillNo":159,"name":160,"nameZh":6,"description":161,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":162,"categories":163,"keywords":164,"publishedAt":39},"01M6KGJGVM0TWW632Y6VQQV2WN","using-streamlit-session-state","Using st.session_state to manage state across Streamlit reruns. Use when persisting data, handling widget state, implementing callbacks, or debugging state issues. Covers initialization patterns, widget-state association, and common gotchas.","https:\u002F\u002Fgithub.com\u002Flegout\u002Fpi-config\u002Fblob\u002Fmain\u002Finstalled-skills\u002Fdeveloping-with-streamlit\u002Fskills\u002Fusing-streamlit-session-state\u002FSKILL.md",[],[165,166,22,167,168,169,170,124,171,24,172,173,174,175,32,176,177],"state","session","session state","using streamlit session state","debugging","issues","common","manage","patterns","across","widget","implementing","initialization",{"skillNo":179,"name":180,"nameZh":6,"description":181,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":182,"categories":183,"keywords":184,"publishedAt":39},"01M6KGJD12GJB7W0ZG66JK00F6","using-streamlit-markdown","Covers all Markdown features in Streamlit including GitHub-flavored syntax plus Streamlit extensions like colored text, badges, Material icons, and LaTeX. Use when formatting text, labels, tooltips, or any text-rendering element.","https:\u002F\u002Fgithub.com\u002Flegout\u002Fpi-config\u002Fblob\u002Fmain\u002Finstalled-skills\u002Fdeveloping-with-streamlit\u002Fskills\u002Fusing-streamlit-markdown\u002FSKILL.md",[],[185,22,186,187,188,189,142,190,24,191,192,193,194,195,196,197],"markdown","using streamlit markdown","github","icons","LaTeX","syntax","formatting","element","material","rendering","extensions","features","labels"]