diff --git a/docs/src/_includes/partials/sidebar.njk b/docs/src/_includes/partials/sidebar.njk index 47e7d44..8b857e8 100644 --- a/docs/src/_includes/partials/sidebar.njk +++ b/docs/src/_includes/partials/sidebar.njk @@ -105,6 +105,7 @@ { label: "Table", url: "/components/table", attrs: link_attrs }, { label: "Tabs", url: "/components/tabs", attrs: link_attrs }, { label: "Textarea", url: "/components/textarea", attrs: link_attrs }, + { label: "Theme Switcher", url: "/components/theme-switcher", attrs: link_attrs }, { label: "Toast", url: "/components/toast", attrs: link_attrs }, { label: "Tooltip", url: "/components/tooltip", attrs: link_attrs } ]} diff --git a/docs/src/components/theme-switcher.njk b/docs/src/components/theme-switcher.njk index f54e4dd..83798df 100644 --- a/docs/src/components/theme-switcher.njk +++ b/docs/src/components/theme-switcher.njk @@ -5,49 +5,107 @@ description: A component that allows the user to switch between light and dark m toc: - label: Usage id: usage - - label: Examples - id: examples children: - - label: Default - id: example-default - - label: Right - id: example-right - - label: Bottom + Start - id: example-bottom-start + - label: HTML + JavaScript + id: usage-html-js + children: + - label: "Step 1: Include the JavaScript script" + id: usage-html-js-1 + - label: "Step 2: Add your switcher" + id: usage-html-js-2 + - label: JavaScript events + id: usage-html-js-3 --- +
+ {% lucide "circle-alert" %} +

There is no dedicated theme switcher component in Basecoat.

+

Instead, we offer a short JavaScript <script> block you can insert in the <head> of your page.

+
+ + {% from "macros/code_preview.njk" import code_preview %} {% from "macros/code_block.njk" import code_block %} -{% set code %}{% endset %} +{% set code %}{% endset %} {{ code_preview("button", code) }} -

Usage

+

Usage

+ +

HTML + JavaScript

+ +

Step 1: Include the JavaScript script

-

On any element, set the value of the data-tooltip attribute to the text you want to display in the tooltip. Additionally, you can set:

- +

Insert the following JavaScript block right at the beginning of the <head> your page. We do this instead of using a separate file to ensure the theme is defined before the page loads, avoiding a flash of unstyled or mist-styled content.

-{% set code %}{% endset %} +{% set code %}{% endset %} {{ code_block(code) }} -

Examples

+

Step 2: Add your switcher

-

Default

+
+

To change the theme, you need to dispatch a basecoat:theme event:

+
-{% set code %}{% endset %} -{{ code_preview("button", code) }} +{% set code %}{% endset %} +{{ code_block(code) }} -

Right

+

JavaScript events

-{% set code %}{% endset %} -{{ code_preview("button", code) }} - -

Bottom + Start

- -{% set code %}{% endset %} -{{ code_preview("button", code) }} \ No newline at end of file +
+
+
basecoat:theme
+
+

By default, the event will toggle the theme, but you can also add a mode to the detail to set the theme explicitly:

+ {% set code_trigger %} + + +{% endset %} + {{ code_block(code_trigger | prettyHtml, "html") }} +
+
+
\ No newline at end of file