Skip to content

Commit

Permalink
[feat](@svelteui/core): add Switch innerLabelSize property (#440)
Browse files Browse the repository at this point in the history
* [@svelteui/core]: added Switch innerLabelSize property

* [@svelteui/core]: modified Switch onLabel position calculation

* [fix](docs): fix small typo in the new prop for Switch

* [feat](@svelteui/core): more stories for Switch

---------

Co-authored-by: Ana Margarida <[email protected]>
  • Loading branch information
xon52 and BeeMargarida authored Aug 20, 2023
1 parent b96c2d7 commit c487a92
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
2 changes: 2 additions & 0 deletions apps/docs/src/routes/core/switch/+page.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Switch component is used to enable/disable something, normally used for boolean

There is support for inserting text inside the switch for when it is enabled and/or disabled. It is also possible to control the size of the switch with predefined values: `xs`, `sm`, `md`, `lg`, `xl`.

This inner label size can be overridden using the `insideLabelSize` property.

<Demo demo={SwitchDemos.inner} />

## Accessibility
Expand Down
1 change: 1 addition & 0 deletions packages/svelteui-core/src/components/Switch/Switch.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface SwitchProps
color?: SvelteUIColor;
size?: SvelteUINumberSize;
radius?: SvelteUINumberSize;
insideLabelSize?: SvelteUINumberSize;
transitionFunction?: SwitchTimingFunction;
className?: string;
id?: string;
Expand Down
12 changes: 12 additions & 0 deletions packages/svelteui-core/src/components/Switch/Switch.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,15 @@
<Story name="Disabled" id="switchDisabledStory">
<Switch disabled />
</Story>

<Story
name="With label"
id="switchLabelStory"
args={{ label: 'I would like to receive annoying notifications ' }}
/>

<Story
name="With inside label"
id="switchInsideLabelStory"
args={{ size: 'md', onLabel: 'ON', offLabel: 'OFF' }}
/>
18 changes: 15 additions & 3 deletions packages/svelteui-core/src/components/Switch/Switch.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface SwitchStyleParams {
color: SvelteUIColor;
radius: SvelteUINumberSize;
size: SvelteUINumberSize;
insideLabelSize: SvelteUINumberSize;
transitionFunction: SwitchTimingFunction;
onLabel: string;
offLabel: string;
Expand Down Expand Up @@ -58,7 +59,18 @@ export const sizes = {
};

export default createStyles(
(theme, { radius, size, transitionFunction, color, offLabel, onLabel }: SwitchStyleParams) => {
(
theme,
{
radius,
size,
transitionFunction,
color,
offLabel,
onLabel,
insideLabelSize
}: SwitchStyleParams
) => {
return {
root: {
display: 'flex',
Expand All @@ -83,7 +95,7 @@ export default createStyles(
appearance: 'none',
display: 'flex',
alignItems: 'center',
fontSize: sizes[size].insideLabelFont,
fontSize: insideLabelSize || sizes[size].insideLabelFont,
fontWeight: 600,

[`${dark.selector} &`]: {
Expand Down Expand Up @@ -142,7 +154,7 @@ export default createStyles(
},

'&::after': {
transform: 'translateX(-200%)',
left: '10%',
content: onLabel ? `'${onLabel}'` : "''",
color: 'White'
}
Expand Down
2 changes: 2 additions & 0 deletions packages/svelteui-core/src/components/Switch/Switch.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
color: $$Props['color'] = 'blue',
size: $$Props['size'] = 'sm',
radius: $$Props['radius'] = 'xl',
insideLabelSize: $$Props['insideLabelSize'] = undefined,
transitionFunction: $$Props['transitionFunction'] = 'linear',
id: $$Props['id'] = randomID(),
label: $$Props['label'] = '',
Expand All @@ -31,6 +32,7 @@
color,
offLabel,
onLabel,
insideLabelSize,
radius,
size,
transitionFunction
Expand Down

0 comments on commit c487a92

Please sign in to comment.