Skip to content

Commit

Permalink
feat: add switch
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanSalt committed Jul 4, 2023
1 parent a3e7628 commit 958f0c8
Show file tree
Hide file tree
Showing 12 changed files with 535 additions and 209 deletions.
1 change: 1 addition & 0 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default defineConfig({
items: [
{ text: 'Checkbox', link: '/components/checkbox' },
{ text: 'Select', link: '/components/select' },
{ text: 'Switch', link: '/components/switch' },
],
},
{
Expand Down
4 changes: 2 additions & 2 deletions docs/components/checkbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ import { RCheckbox } from 'roughness'
</template>
<template #body:reactions.default>

`['focus', 'active']`
`['focus-within', 'active']`

</template>
<template #body:reactions.description>
Expand Down Expand Up @@ -228,7 +228,7 @@ import { RCheckbox } from 'roughness'

</template>
<template #body:update:checked.description>
Callback function triggered when checked state of the checkbox are changed.
Callback function triggered when checked state of the checkbox is changed.
</template>
</RTable>
</RSpace>
Expand Down
2 changes: 1 addition & 1 deletion docs/components/details.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function toggle() {

</template>
<template #body:update:open.description>
Callback function triggered when visibility of the details are changed.
Callback function triggered when visibility of the detail is changed.
</template>
</RTable>
</RSpace>
Expand Down
2 changes: 1 addition & 1 deletion docs/components/select.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts" setup>
import { RCheckbox, RSelect, RDetails, RSpace, RTable } from 'roughness'
import { RCheckbox, RDetails, RSelect, RSpace, RTable } from 'roughness'
</script>

# Select
Expand Down
187 changes: 187 additions & 0 deletions docs/components/switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
<script lang="ts" setup>
import { RDetails, RSpace, RSwitch, RTable } from 'roughness'
</script>

# Switch

Everybody 1-2-Switch!

## Example

<RDetails>
<template #summary>Show Code</template>

```vue
<script lang="ts" setup>
import { RSwitch } from 'roughness'
</script>
<template>
<RSwitch>Airplane Mode</RSwitch>
</template>
```

</RDetails>

<RSwitch>Airplane Mode</RSwitch>

## Usage

### Props

<RSpace overflow>
<RTable
:columns="['name', 'type', 'default', 'description']"
:rows="['model-value', 'reactions']"
>
<template #body:*.name="{ row }">{{ row }}</template>
<template #body:model-value.type>

`boolean`

</template>
<template #body:model-value.default>

`false`

</template>
<template #body:model-value.description>
State of the switch.
</template>

<template #body:reactions.type>

`string[]`

</template>
<template #body:reactions.default>

`['focus-within', 'active']`

</template>
<template #body:reactions.description>

States that trigger graphics redrawing.

See [Reactions](/guide/theme#reactions).

</template>
</RTable>
</RSpace>

### Event

<RSpace overflow>
<RTable
:columns="['name', 'parameters', 'description']"
:rows="['update:model-value']"
>
<template #body:*.name="{ row }">{{ row }}</template>
<template #body:update:model-value.parameters>

`(value: boolean)`

</template>
<template #body:update:model-value.description>
Callback function triggered when state of the switch is changed.
</template>
</RTable>
</RSpace>

### Slots

<RSpace overflow>
<RTable
:columns="['name', 'parameters', 'description']"
:rows="['default']"
>
<template #body:*.name="{ row }">{{ row }}</template>
<template #body:default.description>
Label of the switch.
</template>
</RTable>
</RSpace>

### Styles

<RSpace overflow>
<RTable
:columns="['name', 'values', 'default', 'description']"
:rows="['border-color', 'border-width', 'control-size', 'track-color', 'handle-color']"
>
<template #body:*.name="{ row }">--r-switch-{{ row }}</template>
<template #body:border-color.values>

`<color>`

</template>
<template #body:border-color.default>

`var(--r-common-text-color)`

</template>
<template #body:border-color.description>
Color of the switch control border.
</template>

<template #body:border-width.values>

`<integer>`

</template>
<template #body:border-width.default>

`2` when focused or active, `1` else

</template>
<template #body:border-width.description>
Width of the switch control border.
</template>

<template #body:control-size.values>

`<length>`

</template>
<template #body:control-size.default>

`var(--r-common-line-height)`

</template>
<template #body:control-size.description>
Size of the switch control.
</template>

<template #body:track-color.values>

`<color>`

</template>
<template #body:track-color.default>

`var(--r-common-primary-color)`

</template>
<template #body:track-color.description>
Color of the switch track when open.
</template>

<template #body:handle-color.values>

`<color>`

</template>
<template #body:handle-color.default>

`var(--r-common-background-color)`

</template>
<template #body:handle-color.description>
Color of the switch handle.
</template>
</RTable>
</RSpace>
4 changes: 2 additions & 2 deletions docs/guide/theme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts" setup>
import { RButton, RCheckbox, RDetails, RSpace, RTable, RText, useDark } from 'roughness'
import { RButton, RDetails, RSpace, RSwitch, RTable, RText, useDark } from 'roughness'

const dark = useDark()
</script>
Expand All @@ -14,7 +14,7 @@ In dark and light mode, in addition to the foreground and background colors, the

<RSpace vertical>
<RSpace>
<RCheckbox v-model:checked="dark">Enable dark mode</RCheckbox>
<RSwitch v-model="dark">Enable dark mode</RSwitch>
</RSpace>
<RSpace>
<RButton filled>Normal</RButton>
Expand Down
Loading

0 comments on commit 958f0c8

Please sign in to comment.