Skip to content

Commit 2dd96cd

Browse files
committed
add SfSwitch
1 parent 7cb07ef commit 2dd96cd

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { component$ } from '@builder.io/qwik';
2+
import { SfSwitchProps } from './types';
3+
4+
export const SfSwitch = component$<SfSwitchProps>(({ ref, invalid, class: _class, ...attributes }) => (
5+
<input
6+
{...(ref ? { ref } : {})}
7+
class={`appearance-none h-5 min-w-[36px] bg-transparent border-2 border-gray-500 rounded-full relative ease-in-out duration-300
8+
hover:border-primary-800 hover:before:checked:bg-white checked:before:left-1/2 checked:before:ml-0 checked:before:mr-0.5 disabled:before:bg-gray-500/50
9+
hover:before:bg-primary-800 active:border-primary-800 active:before:bg-primary-800 checked:bg-none checked:bg-primary-700 checked:border-primary-700
10+
checked:before:bg-white hover:checked:bg-primary-800 hover:checked:border-primary-800 disabled:border-gray-500/50 checked:disabled:before:bg-white
11+
checked:disabled:bg-gray-500/50 checked:disabled:border-0 before:transition-all before:w-3.5 before:h-3.5 before:bg-gray-500 before:absolute before:top-0
12+
before:bottom-0 before:my-auto before:rounded-full before:left-0 before:ml-0.5 before:ease-in-out before:duration-300 cursor-pointer disabled:cursor-not-allowed
13+
focus-visible:outline focus-visible:outline-offset
14+
${
15+
invalid
16+
? 'border-negative-700 hover:border-negative-800 active:border-negative-900 before:bg-negative-900'
17+
: ''
18+
}
19+
${_class}`}
20+
type="checkbox"
21+
role="switch"
22+
{...attributes}
23+
data-testid="switch"
24+
/>
25+
));
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './types';
2+
3+
export { SfSwitch } from './SfSwitch';
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {
2+
PropFunction,
3+
QwikChangeEvent,
4+
QwikIntrinsicElements,
5+
Signal,
6+
} from '@builder.io/qwik';
7+
8+
export type SfSwitchProps = Omit<QwikIntrinsicElements['input'], 'children'> & {
9+
ref?: Signal<Element | undefined>;
10+
class?: string;
11+
invalid?: boolean;
12+
onChange$: PropFunction<(event: QwikChangeEvent<HTMLInputElement>) => void>;
13+
};

0 commit comments

Comments
 (0)