Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 79c8360
Author: Francesco Improta <francesco@designabile.com>
Date:   Fri Aug 19 16:17:20 2022 +0200

    Added min css

commit f65deaf
Author: Francesco Improta <francesco@designabile.com>
Date:   Fri Aug 19 16:17:15 2022 +0200

    Added doc page

commit 574c818
Author: Francesco Improta <francesco@designabile.com>
Date:   Fri Aug 19 16:06:49 2022 +0200

    Changed input display

commit c66259b
Author: Francesco Improta <francesco@designabile.com>
Date:   Fri Aug 19 16:04:20 2022 +0200

    Changed html

commit 6742fc9
Author: Francesco Improta <francesco@designabile.com>
Date:   Thu Aug 18 16:44:27 2022 +0200

    Added toggle variables

commit 480bddd
Author: Francesco Improta <francesco@designabile.com>
Date:   Wed Aug 17 17:39:36 2022 +0200

    Removed margin

commit cadb106
Author: Francesco Improta <francesco@designabile.com>
Date:   Wed Aug 17 17:38:59 2022 +0200

    Added toggle
  • Loading branch information
zetareticoli committed Aug 22, 2022
1 parent 49dfe82 commit 9494414
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
57 changes: 57 additions & 0 deletions content/docs/components/toggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
title: "Toggle"
description: "A toggle button allows the user to change a setting between two states."
lead: "A toggle button allows the user to change a setting between two states."
date: 2022-08-18T13:26:54+01:00
lastmod: 2022-08-18T13:26:54+01:00
draft: false
images: []
menu:
docs:
parent: "components"
weight: 610
toc: true
---

Commonly used in websites, mobile apps, and other software, it provides the users a way to choose between two different states.

<div class="preview">
<link rel="stylesheet" href="/cssui/cssui.min.css">
<link rel="stylesheet" href="/cssui/cssui.toggle.min.css">

<input type="checkbox" id="toggle" name="toggle" data-toggle-input checked/>
<label for="toggle" data-toggle></label>
</div>

## Usage

Add the `data-toggle-input` and `data-toggle` attributes to a standard `<input type="checkbox">` and `<label>` HTML tags respectively. Done.

### Code example

```html
<input type="checkbox" name="toggle" data-toggle-input checked/>
<label for="toggle" data-toggle></label>
```

## Customization
The toggle comes with the following customization options:
- background color
- size
- radius
- animation

## Variables

List of variables used. Customize the component's design by changing or overriding these values:

```css
--toggle-width: 60px;
--toggle-height: calc(var(--toggle-width)/2);
--toggle-radius: 18px;
--toggle-background: var(--cssui-gray-light);
--toggle-padding: 10px;
--toggle-animation: ease-in-out;
--toggle-animation-time: .2s;
--toggle-switch-color: #fff;
```
8 changes: 8 additions & 0 deletions lib/src/toggle/toggle.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<body>
<link rel="stylesheet" href="../cssui.css">
<link rel="stylesheet" href="toggle.css">

<input type="checkbox" id="toggle" name="toggle" data-toggle-input checked/>
<label for="toggle" data-toggle></label>

</body>
56 changes: 56 additions & 0 deletions lib/src/toggle/toggle.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[data-toggle] {
--toggle-width: 60px;
--toggle-height: calc(var(--toggle-width)/2);
--toggle-radius: 18px;
--toggle-background: var(--cssui-gray-light);
--toggle-padding: 10px;
--toggle-animation: ease-in-out;
--toggle-animation-time: .2s;
--toggle-switch-color: #fff;
}

[data-toggle] {
position: relative;
display: block;
width: var(--toggle-width);
height: var(--toggle-height);
padding: var(--toggle-padding);
border-radius: var(--toggle-radius);
background: var(--toggle-background);
cursor: pointer;
}

[data-toggle-input],
[data-toggle-input]:active {
display: none;
}

[data-toggle]:before {
position: absolute;
top: 0;
right: auto;
left: 0;
z-index: 1;
content: '';
display: block;
width: var(--toggle-height);
height: var(--toggle-height);
border-radius: 100%;
background: var(--toggle-switch-color);
line-height: 34px;
text-indent: var(--toggle-height);
transition: left var(--toggle-animation-time) var(--toggle-animation);
}

[data-toggle-input] + [data-toggle] {
box-shadow: inset 0 0 0 0 var(--cssui-primary), 0 0 0 2px var(--toggle-background);
}

[data-toggle-input]:checked + [data-toggle]:before {
left: calc(100% - var(--toggle-height));
box-shadow: 0 0 0 2px transparent, 0 3px 3px rgba(0, 0, 0, .3);
}

[data-toggle-input]:checked+[data-toggle] {
box-shadow: inset 0 0 0 18px var(--cssui-primary), 0 0 0 2px var(--cssui-primary);
}
1 change: 1 addition & 0 deletions static/cssui/cssui.toggle.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9494414

Please sign in to comment.