File tree Expand file tree Collapse file tree 4 files changed +83
-55
lines changed
platforms/metagram/src/lib/ui Expand file tree Collapse file tree 4 files changed +83
-55
lines changed Original file line number Diff line number Diff line change 44
55 interface IInputProps extends HTMLInputAttributes {
66 type: HTMLInputTypeAttribute ;
7- selected? : string ;
8- name? : string ;
97 input? : HTMLInputElement ;
108 value: string | number | any ;
119 placeholder? : string ;
1513 type = ' text' ,
1614 input = $bindable (),
1715 value = $bindable (),
18- selected = $bindable (),
19- name = ' ' ,
2016 placeholder = ' ' ,
2117 ... restProps
2218 }: IInputProps = $props ();
2319
24- let radioElement: HTMLInputElement | null = $state (null );
25-
2620 const cbase =
2721 ' w-full bg-grey py-3.5 px-6 text-[15px] text-black-800 font-geist font-normal placeholder:text-black-600 rounded-4xl outline-0 border border-transparent invalid:border-red invalid:text-red focus:invalid:text-black-800 focus:invalid:border-transparent' ;
28-
29- const customRadioStyles = $derived ({
30- common: " before:h-4.5 before:w-4.5 before:border-brand-burnt-orange before:-left-0.75 before:-bottom-0.25 relative before:absolute before:rounded-full before:border-2 before:bg-white before:content-['']" ,
31- selected:
32- ' after:h-2.5 after:w-2.5 after:bg-brand-burnt-orange after:absolute after:bottom-0.75 after:left-0.25 after:rounded-full'
33- });
3422 </script >
3523
36- {#if type === ' radio' }
37- <div
38- class ={cn (
39- [customRadioStyles .common , selected === value ? customRadioStyles .selected : ' ' ].join (
40- ' '
41- )
42- )}
43- aria-checked ={selected === value }
44- role =" radio"
45- tabindex =" 0"
46- onclick ={() => radioElement ?.click ()}
47- onkeypress ={() => radioElement ?.click ()}
48- >
49- <input
50- {...restProps }
51- type =" radio"
52- {value }
53- bind:group ={selected }
54- bind:this ={radioElement }
55- {name }
56- checked ={selected === value }
57- class ={cn ([cbase , restProps .class ].join (' ' ))}
58- tabindex =" 0"
59- />
60- </div >
61- {:else }
62- <input
63- {...restProps }
64- {type }
65- {placeholder }
66- bind:this ={input }
67- bind:value
68- class ={cn ([cbase , restProps .class ].join (' ' ))}
69- tabindex =" 0"
70- />
71- {/if }
24+ <input
25+ {...restProps }
26+ {type }
27+ {placeholder }
28+ bind:this ={input }
29+ bind:value
30+ class ={cn ([cbase , restProps .class ].join (' ' ))}
31+ tabindex =" 0"
32+ />
Original file line number Diff line number Diff line change 1+ import { InputRadio } from ".." ;
2+
3+ export default {
4+ title : "UI/InputRadio" ,
5+ component : InputRadio ,
6+ tags : [ "autodocs" ] ,
7+ render : ( args : { type : string ; placeholder : string } ) => ( {
8+ Component : InputRadio ,
9+ props : args ,
10+ } ) ,
11+ } ;
12+
13+ export const Radio = {
14+ args : {
15+ type : "radio" ,
16+ value : "option1" ,
17+ name : "option-1" ,
18+ } ,
19+ } ;
Original file line number Diff line number Diff line change 1+ <script lang =" ts" >
2+ import { cn } from ' $lib/utils' ;
3+ import type { HTMLAttributes } from ' svelte/elements' ;
4+
5+ interface IInputRadioProps extends HTMLAttributes <HTMLElement > {
6+ selected? : string ;
7+ name? : string ;
8+ value: string ;
9+ }
10+
11+ let {
12+ value = ' ' ,
13+ selected = $bindable (' ' ),
14+ name = ' ' ,
15+ ... restProps
16+ }: IInputRadioProps = $props ();
17+
18+ let radioElement: HTMLInputElement | null = $state (null );
19+
20+ const cbase =
21+ " before:h-4.5 before:w-4.5 before:border-brand-burnt-orange before:-left-0.75 before:-bottom-0.25 relative before:absolute before:rounded-full before:border-2 before:bg-white before:content-['']" ;
22+ </script >
23+
24+ <input
25+ {...restProps }
26+ type =" radio"
27+ {value }
28+ bind:group ={selected }
29+ bind:this ={radioElement }
30+ {name }
31+ checked ={selected === value }
32+ class ={cn ([' hidden' , restProps .class ].join (' ' ))}
33+ />
34+
35+ <span
36+ {...restProps }
37+ class ={cn ([cbase , restProps .class ].join (' ' ))}
38+ role =" radio"
39+ tabindex =" 0"
40+ aria-checked ={selected === value }
41+ onclick ={() => radioElement ?.click ()}
42+ >
43+ {#if selected === value }
44+ <span class =" bg-brand-burnt-orange bottom-0.75 left-0.25 absolute h-2.5 w-2.5 rounded-full"
45+ ></span >
46+ {/if }
47+ </span >
Original file line number Diff line number Diff line change 1- export { default as Button } from './Button/Button.svelte' ;
2- export { default as Avatar } from './Avatar/Avatar.svelte' ;
3- export { default as Input } from './Input/Input.svelte' ;
4- export { default as Select } from './Select/Select.svelte' ;
5- export { default as Label } from './Label/Label.svelte' ;
6- export { default as Toggle } from './Toggle/Toggle.svelte' ;
7- export { default as Helper } from './Helper/Helper.svelte' ;
1+ export { default as Button } from "./Button/Button.svelte" ;
2+ export { default as Avatar } from "./Avatar/Avatar.svelte" ;
3+ export { default as Input } from "./Input/Input.svelte" ;
4+ export { default as Select } from "./Select/Select.svelte" ;
5+ export { default as Label } from "./Label/Label.svelte" ;
6+ export { default as Toggle } from "./Toggle/Toggle.svelte" ;
7+ export { default as Helper } from "./Helper/Helper.svelte" ;
8+ export { default as InputRadio } from "./InputRadio/InputRadio.svelte" ;
You can’t perform that action at this time.
0 commit comments