Thanks to visit codestin.com
Credit goes to github.com

Skip to content
6 changes: 2 additions & 4 deletions src/components/Button.astro
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ const {
>
<Avatar src={avatar} />
<Icon name={icon} />
<slot>
<Fragment set:html={html} />
<Fragment set:text={text} />
</slot>
<Fragment set:html={html} />
<Fragment set:text={text} />
</Root>

<style is:global lang="scss">
Expand Down
46 changes: 46 additions & 0 deletions src/components/Toggle.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
import type { Polymorphic } from 'astro/types'
import { uid } from 'radash'
import Button from './Button.astro'

type Props<As extends 'label'> = Polymorphic<{ as: As }> & {
color?: 'base' | 'brand' | undefined
id?: string | undefined
name?: string | undefined
icon?: string | undefined
html?: string | undefined
text?: string | undefined
toggled: boolean | undefined
}

const { id = uid(7), toggled, name, ...rest } = Astro.props
---

<input
class="toggle-checkbox"
checked={toggled}
type="checkbox"
id={id}
name={name ?? id}
/>

<Button
class:list="toggle"
variant="tertiary"
as="label"
for={id}
{...rest}
/>

<style is:global lang="scss">
@layer fulldev {
.toggle-checkbox {
display: none;

&:checked + .toggle {
background-color: var(--color-5);
color: var(--base-12);
}
}
}
</style>
32 changes: 32 additions & 0 deletions src/content/pages/base/toggle.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
_layout: ComponentLayout
settings: components

title: Toggle
---

# Toggle

import PropsTable from 'fulldev-ui/components/docs/PropsTable.astro'

```astro live
---
import Toggle from 'fulldev-ui/components/Toggle.astro'
---

<Toggle text="Click me" icon="click" />
```

## Props

<PropsTable />

## Examples

```astro live
---
import Toggle from 'fulldev-ui/components/Toggle.astro'
---

<Toggle icon={'code'} text="Auto save" toggled={true} />
```