Skip to content

Commit 7cb07ef

Browse files
committed
add SfSelect
1 parent 4637055 commit 7cb07ef

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import { Slot, component$, useSignal } from '@builder.io/qwik';
2+
import { SfSelectSize } from '../../shared/SfSelect';
3+
import { SfIconExpandMore } from '../SfIcons';
4+
import { SfSelectProps } from './types';
5+
6+
export const SfSelect = component$<SfSelectProps>(
7+
({
8+
size = SfSelectSize.base,
9+
children,
10+
invalid,
11+
wrapperClass,
12+
showSlotChevron,
13+
required,
14+
disabled,
15+
class: _class,
16+
placeholder,
17+
// onBlur,
18+
onChange$,
19+
// onClick,
20+
// onKeyDown,
21+
...attributes
22+
}) => {
23+
// TODO
24+
// const { isFocusVisible } = useFocusVisible();
25+
const isFocusVisible = false;
26+
27+
const chevronRotatedSignal = useSignal(false);
28+
29+
// const rotateUp = $(() => {chevronRotatedSignal.value = (true)});
30+
31+
// const rotateDown = $(() => {chevronRotatedSignal.value =(false)});
32+
33+
// const keydownHandler = $((event: QwikKeyboardEvent<HTMLSelectElement>) => {
34+
// if (event.key === 'Space') {
35+
// rotateUp();
36+
// }
37+
// });
38+
39+
return (
40+
<div
41+
class={`relative flex flex-col rounded-md ${
42+
isFocusVisible
43+
? 'focus-within:outline focus-within:outline-offset'
44+
: ''
45+
} ${wrapperClass}`}
46+
data-testid="select"
47+
>
48+
<select
49+
required={required}
50+
disabled={disabled}
51+
class={`
52+
appearance-none disabled:cursor-not-allowed cursor-pointer pl-4 pr-3.5 text-neutral-900 focus:ring-primary-700 focus:ring-2 outline-none bg-transparent rounded-md ring-1 ring-inset ring-neutral-300 hover:ring-primary-700 active:ring-2 active:ring-primary-700 disabled:bg-disabled-100 disabled:text-disabled-900 disabled:ring-disabled-200
53+
${size === SfSelectSize.sm ? 'py-1.5' : ''}
54+
${size === SfSelectSize.base ? 'py-2' : ''}
55+
${size === SfSelectSize.lg ? 'py-3 text-base' : ''}
56+
${invalid && !disabled ? '!ring-negative-600 ring-2' : ''}
57+
${_class}`}
58+
data-testid="select-input"
59+
onChange$={onChange$}
60+
// TODO
61+
// onBlur={composeHandlers(rotateDown, onBlur)}
62+
// onChange={composeHandlers(rotateDown, onChange)}
63+
// onClick={composeHandlers(rotateUp, onClick)}
64+
// onKeyDown={composeHandlers(keydownHandler, onKeyDown)}
65+
{...attributes}
66+
>
67+
{placeholder && (
68+
<option
69+
value=""
70+
class={`bg-neutral-300 text-sm ${
71+
size === SfSelectSize.lg ? 'text-base' : ''
72+
}`}
73+
data-testid="select-placeholder"
74+
>
75+
{placeholder}
76+
</option>
77+
)}
78+
<Slot />
79+
</select>
80+
{showSlotChevron ? (
81+
<Slot name="chevron" />
82+
) : (
83+
<SfIconExpandMore
84+
class={`
85+
box-border absolute -translate-y-1 pointer-events-none top-1/3 right-4 transition easy-in-out duration-0.5
86+
${disabled ? 'text-disabled-500' : 'text-neutral-500'}
87+
${chevronRotatedSignal.value ? 'rotate-180' : ''}`}
88+
/>
89+
)}
90+
</div>
91+
);
92+
}
93+
);
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 { SfSelect } from './SfSelect';
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {
2+
PropFunction,
3+
QwikChangeEvent,
4+
QwikIntrinsicElements,
5+
} from '@builder.io/qwik';
6+
import { SfSelectSize } from '../../shared/SfSelect';
7+
8+
export type SfSelectProps = Omit<QwikIntrinsicElements['select'], 'size'> & {
9+
class?: string;
10+
size?: `${SfSelectSize}`;
11+
invalid?: boolean;
12+
wrapperClass?: string;
13+
showSlotChevron?: boolean;
14+
onChange$?: PropFunction<(event: QwikChangeEvent<HTMLSelectElement>) => void>;
15+
};

0 commit comments

Comments
 (0)