Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd4867b9

Browse files
authored
fix: sfChip square (qwikifiers#46)
1 parent4a7386f commitd4867b9

File tree

1 file changed

+85
-0
lines changed
  • packages/qwik-storefront-ui/src/components/SfChip

1 file changed

+85
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import{Slot,component$,useId}from'@builder.io/qwik';
2+
import{SfChipProps,SfChipSize}from'./types';
3+
4+
exportconstSfChip=component$<SfChipProps>(
5+
({
6+
size=SfChipSize.base,
7+
class:_class,
8+
slotPrefix,
9+
slotSuffix,
10+
inputProps,
11+
square=false,
12+
ref,
13+
onChange$,
14+
...attributes
15+
}:SfChipProps)=>{
16+
constchipId=useId();
17+
constpaddingForSize=(
18+
size: `${SfChipSize}`,
19+
square:boolean,
20+
slotPrefix:boolean,
21+
slotSuffix:boolean
22+
)=>{
23+
switch(size){
24+
caseSfChipSize.sm:
25+
returnsquare
26+
?'px-1.5 rounded-none'
27+
:[slotPrefix ?'pl-1.5' :'pl-3',slotSuffix ?'pr-1.5' :'pr-3'];
28+
default:
29+
returnsquare
30+
?'px-2 rounded-none'
31+
:[slotPrefix ?'pl-2' :'pl-4',slotSuffix ?'pr-2' :'pr-4'];
32+
}
33+
};
34+
constgetSizeClasses=(size:SfChipProps['size'])=>{
35+
switch(size){
36+
caseSfChipSize.sm:
37+
return`text-sm py-1.5 gap-1.5`;
38+
default:
39+
return'text-base py-2 gap-2';
40+
}
41+
};
42+
43+
constgetCheckedClasses=(checked:boolean|undefined)=>{
44+
returnchecked
45+
?'ring-2 ring-primary-700 hover:ring-primary-700'
46+
:' hover:ring-primary-200 ring-neutral-200';
47+
};
48+
49+
constgetDisabledClasses=(disabled:boolean|undefined)=>{
50+
returndisabled
51+
?'cursor-not-allowed bg-disabled-100 opacity-50 ring-1 ring-disabled-200 hover:ring-disabled-200'
52+
:'hover:bg-primary-100 cursor-pointer';
53+
};
54+
55+
return(
56+
<>
57+
<input
58+
id={chipId}
59+
{...(ref ?{ ref} :{})}
60+
class="hidden"
61+
type="checkbox"
62+
{...inputProps}
63+
onChange$={(e)=>onChange$&&onChange$(e)}
64+
/>
65+
<label
66+
for={chipId}
67+
class={[
68+
'ring-1 ring-inset rounded-full inline-flex items-center transition duration-200 justify-center outline-offset-2 outline-secondary-600 focus-visible:outline',
69+
getCheckedClasses(inputProps?.checked),
70+
getDisabledClasses(inputProps?.disabled),
71+
getSizeClasses(size),
72+
paddingForSize(size,square,!!slotPrefix,!!slotSuffix),
73+
_class,
74+
]}
75+
data-testid="chip"
76+
{...attributes}
77+
>
78+
{slotPrefix&&<Slotname="prefix"/>}
79+
<Slot/>
80+
{slotSuffix&&<Slotname="suffix"/>}
81+
</label>
82+
</>
83+
);
84+
}
85+
);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp