From dbe9fc4353a561ae6cbfb19a320576197bf28104 Mon Sep 17 00:00:00 2001
From: Jerry_wu <409187100@qq.com>
Date: Fri, 13 Sep 2024 13:29:50 +0800
Subject: [PATCH 01/25] feat: add a new switch component
---
packages/kit-headless/src/components/switch/index.ts | 1 +
packages/kit-headless/src/components/switch/switch.test.ts | 0
2 files changed, 1 insertion(+)
create mode 100644 packages/kit-headless/src/components/switch/index.ts
create mode 100644 packages/kit-headless/src/components/switch/switch.test.ts
diff --git a/packages/kit-headless/src/components/switch/index.ts b/packages/kit-headless/src/components/switch/index.ts
new file mode 100644
index 000000000..336ce12bb
--- /dev/null
+++ b/packages/kit-headless/src/components/switch/index.ts
@@ -0,0 +1 @@
+export {}
diff --git a/packages/kit-headless/src/components/switch/switch.test.ts b/packages/kit-headless/src/components/switch/switch.test.ts
new file mode 100644
index 000000000..e69de29bb
From a219d8fe55d4d6d2c60882e6d97e53a7f7dda0e8 Mon Sep 17 00:00:00 2001
From: Jerry_wu <409187100@qq.com>
Date: Thu, 19 Sep 2024 19:24:23 +0800
Subject: [PATCH 02/25] init debug
---
.changeset/poor-spiders-clap.md | 6 ++++++
.../src/routes/docs/styled/switch/examples/hero.tsx | 12 ++++++++++++
.../website/src/routes/docs/styled/switch/index.mdx | 5 +++++
.../kit-styled/src/components/switch/switch.tsx | 13 +++++++++++++
packages/kit-styled/src/index.ts | 1 +
5 files changed, 37 insertions(+)
create mode 100644 .changeset/poor-spiders-clap.md
create mode 100644 apps/website/src/routes/docs/styled/switch/examples/hero.tsx
create mode 100644 apps/website/src/routes/docs/styled/switch/index.mdx
create mode 100644 packages/kit-styled/src/components/switch/switch.tsx
diff --git a/.changeset/poor-spiders-clap.md b/.changeset/poor-spiders-clap.md
new file mode 100644
index 000000000..72193b11f
--- /dev/null
+++ b/.changeset/poor-spiders-clap.md
@@ -0,0 +1,6 @@
+---
+'@qwik-ui/headless': major
+'@qwik-ui/styled': major
+---
+
+add a new switch component
diff --git a/apps/website/src/routes/docs/styled/switch/examples/hero.tsx b/apps/website/src/routes/docs/styled/switch/examples/hero.tsx
new file mode 100644
index 000000000..d83b69617
--- /dev/null
+++ b/apps/website/src/routes/docs/styled/switch/examples/hero.tsx
@@ -0,0 +1,12 @@
+import { component$ } from '@builder.io/qwik';
+import { Switch } from '~/components/ui';
+
+
+export default component$(() => {
+ return (
+ <>
+ sdsdsd
+
+ >
+ );
+});
diff --git a/apps/website/src/routes/docs/styled/switch/index.mdx b/apps/website/src/routes/docs/styled/switch/index.mdx
new file mode 100644
index 000000000..22cf1caa3
--- /dev/null
+++ b/apps/website/src/routes/docs/styled/switch/index.mdx
@@ -0,0 +1,5 @@
+---
+title: Qwik UI | Styled Radio Group Component
+---
+
+sdsds
diff --git a/packages/kit-styled/src/components/switch/switch.tsx b/packages/kit-styled/src/components/switch/switch.tsx
new file mode 100644
index 000000000..212ba16ef
--- /dev/null
+++ b/packages/kit-styled/src/components/switch/switch.tsx
@@ -0,0 +1,13 @@
+import { type PropsOf, component$ } from '@builder.io/qwik';
+import { cn } from '@qwik-ui/utils';
+
+
+export const Switch = component$>(({ ...props }) => {
+ return (
+
+ );
+});
diff --git a/packages/kit-styled/src/index.ts b/packages/kit-styled/src/index.ts
index 6c2b24bf7..1746808e8 100644
--- a/packages/kit-styled/src/index.ts
+++ b/packages/kit-styled/src/index.ts
@@ -21,3 +21,4 @@ export * from './components/textarea/textarea';
export * from './components/toggle/toggle';
export * from './components/toggle-group/toggle-group';
export * from './components/dropdown/dropdown';
+export * from './components/switch/switch';
From 7a5f6272498a4e327f8c046a061e796d2eeafb89 Mon Sep 17 00:00:00 2001
From: Jerry_wu <409187100@qq.com>
Date: Tue, 24 Sep 2024 09:26:20 +0800
Subject: [PATCH 03/25] switch is developing
---
.../docs/headless/switch/examples/hero.tsx | 31 ++
.../src/routes/docs/headless/switch/index.mdx | 274 ++++++++++++++++++
.../docs/headless/switch/snippets/switch.css | 0
.../src/components/switch/switch-context.tsx | 12 +
.../src/components/switch/switch-root.tsx | 27 ++
packages/kit-headless/src/index.ts | 1 +
.../src/components/switch/switch.tsx | 14 +-
7 files changed, 354 insertions(+), 5 deletions(-)
create mode 100644 apps/website/src/routes/docs/headless/switch/examples/hero.tsx
create mode 100644 apps/website/src/routes/docs/headless/switch/index.mdx
create mode 100644 apps/website/src/routes/docs/headless/switch/snippets/switch.css
create mode 100644 packages/kit-headless/src/components/switch/switch-context.tsx
create mode 100644 packages/kit-headless/src/components/switch/switch-root.tsx
diff --git a/apps/website/src/routes/docs/headless/switch/examples/hero.tsx b/apps/website/src/routes/docs/headless/switch/examples/hero.tsx
new file mode 100644
index 000000000..e02b83356
--- /dev/null
+++ b/apps/website/src/routes/docs/headless/switch/examples/hero.tsx
@@ -0,0 +1,31 @@
+import { component$, useStyles$ } from '@builder.io/qwik';
+import { Select } from '@qwik-ui/headless';
+
+export default component$(() => {
+ useStyles$(styles);
+ const users = ['Tim', 'Ryan', 'Jim', 'Jessie', 'Abby'];
+
+ return (
+
+ Logged in users
+
+
+
+
+ {users.map((user) => (
+
+ {user}
+
+
+
+
+ ))}
+
+
+ );
+});
+
+// internal
+import styles from '../snippets/select.css?inline';
+import { LuCheck } from '@qwikest/icons/lucide';
+
diff --git a/apps/website/src/routes/docs/headless/switch/index.mdx b/apps/website/src/routes/docs/headless/switch/index.mdx
new file mode 100644
index 000000000..4c12c72d1
--- /dev/null
+++ b/apps/website/src/routes/docs/headless/switch/index.mdx
@@ -0,0 +1,274 @@
+---
+title: Qwik UI | Tabs
+---
+
+import { statusByComponent } from '~/_state/component-statuses';
+
+
+
+# Tabs
+
+Explore and switch between different views using tabs
+
+
+
+## Building blocks
+
+### The full version
+
+
+
+### The short version
+
+
+
+> The "short version" π will be automatically transformed into the full ARIA compliant version
+
+## Vertical
+
+by default, the tabs are horizontal, but you can adjust the underlying behavior to be vertical by setting the `vertical` prop to true.
+
+
+
+## Disabled
+
+You can disable a tab by setting the `disabled` prop to true.
+
+
+
+## Behavior
+
+### Automatic
+
+The default behavior of the tabs is manual, which means that the tabs will automatically switch to the next tab when the user hovers over the tab. You can change this behavior by setting the `behavior` prop to `automatic`.
+
+
+
+### Manual
+
+You can set the behavior to manual, which means that the tabs will not automatically switch to the next tab when the user presses the right arrow key, and to the previous tab when the user presses the left arrow key.
+
+
+
+## Dynamic
+
+
+
+## onSelectedIndexChange$
+
+You can listen to changes in the selected index by subscribing to the `onSelectedIndexChange$` store.
+
+
+
+## bind:selectedIndex
+
+You can provide a signal for the selected index with the `bind:selectedIndex={yourSignal}` and it will be used directly. This is a more efficient version of `onSelectedIndexChange$`.
+
+## bind:selectedTabId
+
+You can provide a signal for the selected tab id with the `bind:selectedTabId={yourSignal}`
+and it will be used directly.
+
+π‘ You can manually set the `tabId` prop on each tab to be able to select any tab by its ID.
+
+
+
+## Add a "selected" prop
+
+You can add a "selected" prop to the Tab component to make it selected by default.
+
+
+
+## onClick$
+
+You can pass a custom `onClick$` handler.
+
+
+
+## Creating reusable Tabs
+
+In order to remove the need for a linking `value` prop for each Tab and Tabs.Panel pair, we have chosen to create the Tabs component as an [inline component](https://qwik.builder.io/docs/components/overview/#inline-components).
+
+By consequence, the Tabs component needs to be aware of its children. If you want to create your custom reusable Tabs.List/Tab/Tabs.Panel components, you will have to pass them to the Tabs component through its `Tabs.List`, `Tab`, and `Tabs.Panel` props:
+
+```tsx
+const CustomTabs = (props: PropsOf) => (
+
+);
+```
+
+
+
+
+ If you don't do the above, the Tabs component cannot know if your CustomTab component is
+ a Tab component.
+
+
+
+
+## Accessibility
+
+### Keyboard interaction
+
+
+
+## API
+
+### Tabs
+
+ void',
+ description: 'An event hook that gets notified whenever the selected index changes',
+ },
+ {
+ name: 'onSelectedTabIdChange$',
+ type: 'function',
+ info: '(index: string) => void',
+ description: 'An event hook that gets notified whenever the selected tabId changes',
+ },
+ {
+ name: 'bind:selectedIndex',
+ type: 'signal',
+ info: 'Signal',
+ description:
+ 'A signal that binds the selected index. This is a more efficient version of `selectedIndex` + `onSelectedIndexChange$`',
+ },
+ {
+ name: 'bind:selectedTabId',
+ type: 'signal',
+ info: 'Signal',
+ description:
+ 'A signal that binds the selected tabId. This is a more efficient version of `selectedTabId` + `onSelectedTabIdChange$`',
+ },
+ {
+ name: 'tabClass',
+ type: 'string',
+ description: 'The class name to apply to tabs',
+ },
+ {
+ name: 'panelClass',
+ type: 'string',
+ description: 'The class name to apply to panels',
+ },
+ ]}
+/>
+
+### Tab
+
+
+
+### Tabs.Panel
+
+{label}`',
+ },
+ {
+ name: 'selected',
+ type: 'boolean',
+ description: 'Select this tab by default',
+ },
+ ]}
+/>
diff --git a/apps/website/src/routes/docs/headless/switch/snippets/switch.css b/apps/website/src/routes/docs/headless/switch/snippets/switch.css
new file mode 100644
index 000000000..e69de29bb
diff --git a/packages/kit-headless/src/components/switch/switch-context.tsx b/packages/kit-headless/src/components/switch/switch-context.tsx
new file mode 100644
index 000000000..17a7db5dd
--- /dev/null
+++ b/packages/kit-headless/src/components/switch/switch-context.tsx
@@ -0,0 +1,12 @@
+import { createContextId, type Signal } from '@builder.io/qwik';
+
+export interface SwitchState {
+ 'bind:checked': Signal;
+ defaultChecked: boolean;
+ disabled: boolean;
+ label: string;
+}
+//
+export type SwitchContextState = Omit & { bindChecked: Signal }
+
+export const SwitchContext = createContextId('SwitchContext');
diff --git a/packages/kit-headless/src/components/switch/switch-root.tsx b/packages/kit-headless/src/components/switch/switch-root.tsx
new file mode 100644
index 000000000..1788a05ed
--- /dev/null
+++ b/packages/kit-headless/src/components/switch/switch-root.tsx
@@ -0,0 +1,27 @@
+import {
+ component$,
+ Slot,
+ useContextProvider,
+ type PropsOf
+} from '@builder.io/qwik';
+import { type SwitchContextState, type SwitchState, SwitchContext } from './switch-context';
+export type SwitchProps = PropsOf<'div'> & SwitchState;
+
+
+
+export const SwitchRoot = component$(({defaultChecked, disabled, label, ...rest}: SwitchProps) => {
+ const context: SwitchContextState = {
+ defaultChecked,
+ disabled,
+ label,
+ bindChecked: rest['bind:checked']
+ }
+
+ useContextProvider(SwitchContext, context)
+
+ return (
+
+
+
+ );
+})
diff --git a/packages/kit-headless/src/index.ts b/packages/kit-headless/src/index.ts
index 77c2e051a..08ad64599 100644
--- a/packages/kit-headless/src/index.ts
+++ b/packages/kit-headless/src/index.ts
@@ -19,3 +19,4 @@ export * as Tooltip from './components/tooltip';
export * as Dropdown from './components/dropdown';
export * as Combobox from './components/combobox';
export { Polymorphic } from './components/polymorphic';
+export * as Switch from './components/switch';
diff --git a/packages/kit-styled/src/components/switch/switch.tsx b/packages/kit-styled/src/components/switch/switch.tsx
index 212ba16ef..15a6649b8 100644
--- a/packages/kit-styled/src/components/switch/switch.tsx
+++ b/packages/kit-styled/src/components/switch/switch.tsx
@@ -4,10 +4,14 @@ import { cn } from '@qwik-ui/utils';
export const Switch = component$>(({ ...props }) => {
return (
-
+