@monabbous/slidebox 0.0.6 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,55 +1,65 @@
1
- # Slidebox
2
- ![Example](https://i.imgur.com/yyRPh0R.gif)
3
- ## [Example (click me)](https://htmlpreview.github.io/?https://github.com/monabbous/slidebox/blob/master/examples/simple.html)
4
- As you can see in the example above, this slidebox is easy to configure with these two css properties, `color` and `font-size`.
5
-
6
- ### Quick Setup
7
- Include in your html
8
-
9
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css"/>
10
- <link rel="stylesheet" href="https://unpkg.com/@monabbous/slidebox@0.0.3/dist/css/slidebox.css"/>
11
-
12
- Add the `slidebox` class
13
-
14
- <input style="font-size: 24px" type="checkbox" class="slidebox">
15
-
16
- ## Installation (Sass)
17
- #### 1. Font Awesome
18
- First you must include **[Font Awesome](https://fontawesome.com)** in your project (Preferable Font Awesome 5).
19
- #### 2. Slidebox
20
-
21
- Using `Sass` with `NPM` just install with
22
-
23
- npm i @monabbous/slidebox
24
-
25
- Then include in your sass style file
26
-
27
- @import '~@monabbous/slidebox';
28
-
29
- ## Usage
30
- Simply in your checkbox element add the slidebox class.
31
-
32
- <input type="checkbox" class="slidebox">
33
-
34
- ### Custom Style
35
- Just like the Example, you can modify the color and the size of the checkbox.
36
-
37
- <input style="font-size: 24px" type="checkbox" class="slidebox">
38
-
39
- Make sure when modifying the color to add class `dark` when using a dark color, and `light` when using a light color.
40
-
41
- <!-- dark color -->
42
- <input style="color:#040491" type="checkbox" class="slidebox dark">
43
-
44
- <!-- light color -->
45
- <input style="color:#a8a8ff" type="checkbox" class="slidebox light">
46
-
47
- You can also invert the visible output of the slide box, where the value of the checkbox is the opposite of how it is shown.
48
-
49
- <input type="checkbox" class="slidebox inverted">
50
-
51
- ### Changing the default Configuration
52
-
53
- $slideboxColorDefaultColor: blue;
54
- $slideboxClassPrefix: 'nabbous-';
55
- @import '~@monabbous/slidebox';
1
+ # Slidebox Lab
2
+
3
+ An elastic CSS switch with a playground for geometry, colors, and motion.
4
+
5
+ [Preview the interactive playground online](https://htmlpreview.github.io/?https://github.com/monabbous/slidebox/blob/main/index.html)
6
+
7
+ ![Slidebox Lab demo: default geometry, 200ms ease-in-out](assets/slidebox-demo.webp)
8
+
9
+ The animation uses the default width (2), thumb spacing (0.33), deformation (0.1), and a 200ms `ease-in-out` transition.
10
+
11
+ ## npm package
12
+
13
+ The published CSS package keeps the name [`@monabbous/slidebox`](https://www.npmjs.com/package/@monabbous/slidebox).
14
+ The package includes the switch stylesheet at `dist/css/slidebox.css` and a Sass-compatible entrypoint at `scss/slidebox.scss`. The playground is not included in npm.
15
+
16
+ ```bash
17
+ npm install @monabbous/slidebox
18
+ ```
19
+
20
+ Import `@monabbous/slidebox/dist/css/slidebox.css` in a stylesheet or through your bundler, then use `<input class="slidebox" type="checkbox">`. The package is built from the component rules in `style.css` using `npm run build`.
21
+
22
+ ## Manual npm releases
23
+
24
+ The release workflow is [Publish to npm](.github/workflows/publish-npm.yml). It is triggered **only** through GitHub Actions > Run workflow on `main`, with a `patch`, `minor`, or `major` choice.
25
+
26
+ The manifest starts at `0.3.0`, so the first `patch` dispatch will release `0.3.1` (once npm credentials are configured). The workflow builds and tests the package, creates a `chore(release): vX.Y.Z` commit and tag, pushes both to `main`, then publishes to npm.
27
+
28
+ Before the first release:
29
+
30
+ 1. In GitHub Settings > General > Default branch, change `master` to `main`.
31
+ 2. Add a granular npm publish token as the repository Actions secret `NPM_TOKEN`, scoped to `@monabbous/slidebox`, with permission to publish. Never commit the token.
32
+ 3. Ensure GitHub Actions has permission to write repository contents.
33
+ 4. Manually dispatch the release workflow on `main`.
34
+
35
+ The workflow does not run on pushes or tags. A failed npm publish after the Git tag has been pushed requires fixing the publish failure for that version before choosing a new bump. The old library is preserved in `legacy/`.
36
+
37
+ ## Run locally
38
+
39
+ Clone this repository, then serve its root directory:
40
+
41
+ ```bash
42
+ python3 -m http.server 8080
43
+ ```
44
+
45
+ Open `http://localhost:8080`. The lab uses plain HTML, CSS, and JavaScript, without a build step.
46
+
47
+ ## Playground
48
+
49
+ - Adjust track width, thumb spacing, press deformation, and transition duration.
50
+ - Change easing family and direction (In, Out, or In-Out), including Elastic and Bounce.
51
+ - Compare Slidebox against native controls in light and dark schemes.
52
+ - Choose browser-default, CSS system, nabous.dev, or custom colors.
53
+ - Copy complete CSS, Tailwind v4 `@utility` CSS, or configuration variables.
54
+
55
+ Chromium currently lacks support for the `AccentColor` CSS color keyword. In browser-default mode, the custom thumb uses a blue approximation in light mode and `SelectedItem` in dark mode, while native controls retain `accent-color: auto`. Browsers that support `AccentColor` use it automatically.
56
+
57
+ Controls can be adjusted without triggering transition animations. The selected duration is restored after two animation frames.
58
+
59
+ The easing functions follow [easings.net](https://easings.net/). Elastic and Bounce use sampled CSS `linear()` timing functions.
60
+
61
+ ## Original Slidebox package
62
+
63
+ The original Sass package, compiled CSS, package manifests, and example are preserved in [`legacy/`](legacy/). See the [legacy README](legacy/README.md) for the previous installation instructions.
64
+
65
+ [Source](https://github.com/monabbous/slidebox) · [nabous.dev](https://nabous.dev)
@@ -1,208 +1,58 @@
1
- @charset "UTF-8";
2
- input[type=checkbox].slidebox {
3
- -webkit-appearance: none !important;
4
- -moz-appearance: none !important;
5
- -ms-appearance: none !important;
6
- -o-appearance: none !important;
7
- appearance: none !important;
8
- height: auto;
9
- width: auto;
10
- line-height: 0px;
11
- position: relative;
12
- color: blue;
13
- outline: 0 !important;
1
+ .slidebox {
2
+ --_container-width-ratio: 2;
3
+ --_thumb-spacing-ratio: .33;
4
+ --_deform: .1;
5
+ --_duration: 200ms;
6
+ --_easing-function: ease-in-out;
7
+ --_track: Field;
8
+ --_border: ButtonBorder;
9
+ --_off: FieldText;
10
+ --_on: light-dark(#0b75ff, SelectedItem);
11
+ appearance: none;
12
+ -webkit-appearance: none;
13
+ box-sizing: border-box;
14
+ display: inline-flex;
15
+ align-items: center;
16
+ justify-content: center;
17
+ width: calc(1em * var(--_container-width-ratio));
18
+ height: 1em;
19
+ font-size: 54px;
20
+ padding: 0;
21
+ border: 1px solid var(--_border);
22
+ border-radius: 100vw;
23
+ background: var(--_track);
14
24
  cursor: pointer;
15
- padding: 0 0.4em;
16
- font-size: 1em;
17
- transform-origin: center center;
18
25
  }
19
- input[type=checkbox].slidebox:focus::after {
20
- outline: auto 5px -webkit-focus-ring-color;
26
+ @supports (color: AccentColor) {
27
+ .slidebox { --_on: AccentColor; }
21
28
  }
22
- input[type=checkbox].slidebox::before {
23
- direction: ltr;
24
- position: absolute;
25
- content: "";
26
- font-weight: 900;
27
- font-family: "Font Awesome 5 Free";
29
+ .slidebox::after {
30
+ --_start: 0; --_end: 1;
31
+ content: "";
28
32
  display: block;
29
- letter-spacing: -0.8em;
30
- margin-left: 0.4em;
31
- left: 50%;
32
- top: 50%;
33
- transform-origin: center center;
34
- -webkit-transform: translate(-50%, -50%) scale(0.8);
35
- transform: translate(-50%, -50%) scale(0.8);
36
- width: 3.2em;
33
+ flex: 1 1 auto;
34
+ min-width: 0;
35
+ width: calc((1 - var(--_thumb-spacing-ratio)) * 1em);
36
+ height: calc((1 - var(--_thumb-spacing-ratio)) * 1em);
37
+ margin-block: calc(var(--_thumb-spacing-ratio) * .5em);
38
+ margin-inline-start: calc((1em * var(--_container-width-ratio) - 1em) * var(--_start) + var(--_thumb-spacing-ratio) * .5em);
39
+ margin-inline-end: calc((1em * var(--_container-width-ratio) - 1em) * var(--_end) + var(--_thumb-spacing-ratio) * .5em);
40
+ border-radius: inherit;
41
+ background: var(--_off);
42
+ transition: background var(--_duration) var(--_easing-function), margin-inline-start var(--_duration) var(--_easing-function), margin-inline-end var(--_duration) var(--_easing-function);
43
+ transition-delay: 0s, 0s, calc(var(--_duration) * var(--_deform));
44
+ }
45
+ .slidebox:checked::after {
46
+ --_start: 1; --_end: 0;
47
+ background: var(--_on);
48
+ transition-delay: 0s, calc(var(--_duration) * var(--_deform)), 0s;
49
+ }
50
+ .slidebox:not(:checked):active::after { --_end: calc(1 - var(--_deform)); }
51
+ .slidebox:checked:active::after { --_start: calc(1 - var(--_deform)); }
52
+ .slidebox:disabled { cursor: not-allowed; opacity: .5; }
53
+ @media (forced-colors: active) {
54
+ .slidebox { --_track: Field; --_border: ButtonBorder; --_off: FieldText; --_on: Highlight; }
55
+ }
56
+ @media (prefers-reduced-motion: reduce) {
57
+ .slidebox::after { transition-duration: .01ms; transition-delay: 0ms; }
37
58
  }
38
- input[type=checkbox].slidebox::after {
39
- line-height: 1em;
40
- position: relative;
41
- content: "";
42
- font-weight: 900;
43
- padding: 0.4em;
44
- font-family: "Font Awesome 5 Free";
45
- display: block;
46
- transform-origin: center center;
47
- animation-duration: 0.2s;
48
- animation-timing-function: cubic-bezier(0.68, -0.6, 0.32, 1.6);
49
- animation-fill-mode: forwards;
50
- filter: drop-shadow(0 0 4px rgba(0, 0, 0, 0.5));
51
- }
52
- input[type=checkbox].slidebox::before, input[type=checkbox].slidebox::after {
53
- transition: color 0.2s ease-in-out;
54
- }
55
- :not([dir=rtl]) input[type=checkbox].slidebox:not(.inverted)::after {
56
- animation-name: slideboxToRight;
57
- }
58
-
59
- [dir=rtl] input[type=checkbox].slidebox:not(.inverted)::after {
60
- animation-name: slideboxToLeft;
61
- }
62
-
63
- input[type=checkbox].slidebox:not(.inverted).dark::before {
64
- color: white;
65
- }
66
- input[type=checkbox].slidebox:not(.inverted).dark::after {
67
- color: #e6e6e6;
68
- }
69
- input[type=checkbox].slidebox:not(.inverted).dark::after {
70
- filter: brightness(130%) drop-shadow(0 0 4px rgba(0, 0, 0, 0.5));
71
- }
72
- input[type=checkbox].slidebox:not(.inverted).light::before {
73
- color: white;
74
- }
75
- input[type=checkbox].slidebox:not(.inverted).light::after {
76
- color: #f7f7f7;
77
- }
78
- input[type=checkbox].slidebox:not(.inverted).light::before {
79
- filter: brightness(70%);
80
- }
81
- input[type=checkbox].slidebox:not(.inverted)::before {
82
- color: white;
83
- }
84
- input[type=checkbox].slidebox:not(.inverted)::after {
85
- color: #f7f7f7;
86
- }
87
- input[type=checkbox].slidebox:not(.inverted)::before {
88
- filter: brightness(70%);
89
- }
90
- input[type=checkbox].slidebox:not(.inverted):checked::before, input[type=checkbox].slidebox:not(.inverted):checked::after {
91
- color: inherit;
92
- }
93
- :not([dir=rtl]) input[type=checkbox].slidebox:not(.inverted):checked::after {
94
- animation-name: slideboxToLeft;
95
- }
96
-
97
- [dir=rtl] input[type=checkbox].slidebox:not(.inverted):checked::after {
98
- animation-name: slideboxToRight;
99
- }
100
-
101
- :not([dir=rtl]) input[type=checkbox].slidebox:not(.inverted):active:checked::after {
102
- -webkit-transform: translateX(calc(-50% + 0.4em)) scale(1.1) !important;
103
- transform: translateX(calc(-50% + 0.4em)) scale(1.1) !important;
104
- }
105
-
106
- [dir=rtl] input[type=checkbox].slidebox:not(.inverted):active:checked::after {
107
- -webkit-transform: translateX(calc(50% - 0.4em)) scale(1.1) !important;
108
- transform: translateX(calc(50% - 0.4em)) scale(1.1) !important;
109
- }
110
-
111
- :not([dir=rtl]) input[type=checkbox].slidebox:not(.inverted):active:not(:checked)::after {
112
- -webkit-transform: translateX(calc(50% - 0.4em)) scale(1.1) !important;
113
- transform: translateX(calc(50% - 0.4em)) scale(1.1) !important;
114
- }
115
-
116
- [dir=rtl] input[type=checkbox].slidebox:not(.inverted):active:not(:checked)::after {
117
- -webkit-transform: translateX(calc(-50% + 0.4em)) scale(1.1) !important;
118
- transform: translateX(calc(-50% + 0.4em)) scale(1.1) !important;
119
- }
120
-
121
- input[type=checkbox].slidebox.inverted::before, input[type=checkbox].slidebox.inverted::after {
122
- color: inherit;
123
- }
124
- :not([dir=rtl]) input[type=checkbox].slidebox.inverted::after {
125
- animation-name: slideboxToLeft;
126
- }
127
-
128
- [dir=rtl] input[type=checkbox].slidebox.inverted::after {
129
- animation-name: slideboxToRight;
130
- }
131
-
132
- input[type=checkbox].slidebox.inverted.dark::after {
133
- filter: brightness(130%) drop-shadow(0 0 4px rgba(0, 0, 0, 0.5));
134
- }
135
- input[type=checkbox].slidebox.inverted.light::before {
136
- filter: brightness(70%);
137
- }
138
- input[type=checkbox].slidebox.inverted::before {
139
- filter: brightness(70%);
140
- }
141
- :not([dir=rtl]) input[type=checkbox].slidebox.inverted:checked::after {
142
- animation-name: slideboxToRight;
143
- }
144
-
145
- [dir=rtl] input[type=checkbox].slidebox.inverted:checked::after {
146
- animation-name: slideboxToLeft;
147
- }
148
-
149
- input[type=checkbox].slidebox.inverted:checked.dark::before {
150
- color: white;
151
- }
152
- input[type=checkbox].slidebox.inverted:checked.dark::after {
153
- color: #e6e6e6;
154
- }
155
- input[type=checkbox].slidebox.inverted:checked.light::before {
156
- color: white;
157
- }
158
- input[type=checkbox].slidebox.inverted:checked.light::after {
159
- color: #f7f7f7;
160
- }
161
- input[type=checkbox].slidebox.inverted:checked::before {
162
- color: white;
163
- }
164
- input[type=checkbox].slidebox.inverted:checked::after {
165
- color: #f7f7f7;
166
- }
167
- :not([dir=rtl]) input[type=checkbox].slidebox.inverted:active:checked::after {
168
- -webkit-transform: translateX(calc(50% - 0.4em)) scale(1.1) !important;
169
- transform: translateX(calc(50% - 0.4em)) scale(1.1) !important;
170
- }
171
-
172
- [dir=rtl] input[type=checkbox].slidebox.inverted:active:checked::after {
173
- -webkit-transform: translateX(calc(-50% + 0.4em)) scale(1.1) !important;
174
- transform: translateX(calc(-50% + 0.4em)) scale(1.1) !important;
175
- }
176
-
177
- :not([dir=rtl]) input[type=checkbox].slidebox.inverted:active:not(:checked)::after {
178
- -webkit-transform: translateX(calc(-50% + 0.4em)) scale(1.1) !important;
179
- transform: translateX(calc(-50% + 0.4em)) scale(1.1) !important;
180
- }
181
-
182
- [dir=rtl] input[type=checkbox].slidebox.inverted:active:not(:checked)::after {
183
- -webkit-transform: translateX(calc(50% - 0.4em)) scale(1.1) !important;
184
- transform: translateX(calc(50% - 0.4em)) scale(1.1) !important;
185
- }
186
-
187
- @keyframes slideboxToLeft {
188
- from {
189
- -webkit-transform: translateX(calc(50% - 0.4em));
190
- transform: translateX(calc(50% - 0.4em));
191
- }
192
- to {
193
- -webkit-transform: translateX(calc(-50% + 0.4em));
194
- transform: translateX(calc(-50% + 0.4em));
195
- }
196
- }
197
- @keyframes slideboxToRight {
198
- from {
199
- -webkit-transform: translateX(calc(-50% + 0.4em));
200
- transform: translateX(calc(-50% + 0.4em));
201
- }
202
- to {
203
- -webkit-transform: translateX(calc(50% - 0.4em));
204
- transform: translateX(calc(50% - 0.4em));
205
- }
206
- }
207
-
208
- /*# sourceMappingURL=slidebox.css.map */
package/package.json CHANGED
@@ -1,30 +1,38 @@
1
1
  {
2
2
  "name": "@monabbous/slidebox",
3
- "version": "0.0.6",
4
- "style": "dist/css/slidebox.css",
5
- "sass": "scss/slidebox.scss",
6
- "keywords": [
7
- "scss",
8
- "switch",
9
- "toggle",
10
- "button",
11
- "css",
12
- "simple",
13
- "style",
14
- "slidebox",
15
- "checkbox"
3
+ "version": "1.0.0",
4
+ "description": "Elastic, system-color-aware CSS checkbox switch.",
5
+ "license": "ISC",
6
+ "style": "./dist/css/slidebox.css",
7
+ "sass": "./scss/slidebox.scss",
8
+ "files": [
9
+ "dist/css/slidebox.css",
10
+ "scss/slidebox.scss"
16
11
  ],
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
17
15
  "repository": {
18
16
  "type": "git",
19
- "url": "https://github.com/monabbous/slidebox.git"
17
+ "url": "git+https://github.com/monabbous/slidebox.git"
18
+ },
19
+ "homepage": "https://github.com/monabbous/slidebox#readme",
20
+ "bugs": {
21
+ "url": "https://github.com/monabbous/slidebox/issues"
20
22
  },
21
23
  "scripts": {
22
- "build": "sass scss/slidebox.scss dist/css/slidebox.css",
23
- "watch": "sass scss/slidebox.scss dist/css/slidebox.css --watch"
24
+ "build": "node scripts/build.mjs",
25
+ "test": "node --test tests/*.test.mjs",
26
+ "prepack": "npm run build"
24
27
  },
25
- "author": "Mohamed Nabous <mohamed.nabbous@gmail.com>",
26
- "license": "ISC",
27
- "devDependencies": {
28
- "sass": "^1.28.0"
29
- }
28
+ "keywords": [
29
+ "slidebox",
30
+ "switch",
31
+ "toggle",
32
+ "checkbox",
33
+ "css",
34
+ "scss",
35
+ "elastic",
36
+ "system-colors"
37
+ ]
30
38
  }
@@ -1,266 +1,58 @@
1
- $slideboxColorDefaultColor: blue !default;
2
- $slideboxClassPrefix: '' !default;
3
-
4
- $spacing: 0.8em;
5
-
6
- $slideboxShadowFilter: drop-shadow(0 0 4px rgba(black, 0.5));
7
-
8
- @mixin dark-filters() {
9
-
10
- &::after {
11
- filter: brightness(130%) $slideboxShadowFilter;
12
- }
13
- }
14
-
15
- @mixin dark-colors() {
16
- &::before {
17
- color: lighten(grey, 50%);
18
- }
19
-
20
- &::after {
21
- color: lighten(grey, 40%);
22
- }
23
- }
24
-
25
- @mixin light-filters() {
26
- &::before {
27
- filter: brightness(70%);
28
- }
29
- }
30
-
31
- @mixin light-colors() {
32
- &::before {
33
- color: lighten(grey, 50%);
34
- }
35
-
36
- &::after {
37
- color: lighten(#444444, 70%);
38
- }
39
- }
40
-
41
- @mixin slideboxRight($extraTransform: null) {
42
- -webkit-transform: translateX(calc(50% - #{$spacing / 2})) $extraTransform;
43
- transform: translateX(calc(50% - #{$spacing / 2})) $extraTransform;
44
- }
45
-
46
-
47
- @mixin slideboxLeft($extraTransform: null) {
48
- -webkit-transform: translateX(calc(-50% + #{$spacing / 2})) $extraTransform;
49
- transform: translateX(calc(-50% + #{$spacing / 2})) $extraTransform;
50
- }
51
-
52
-
53
- @mixin slideboxStart($extraTransform: null) {
54
- @at-root :not([dir=rtl]) & {
55
- @include slideboxLeft($extraTransform);
56
- }
57
- @at-root [dir=rtl] & {
58
- @include slideboxRight($extraTransform);
59
- }
60
- }
61
-
62
- @mixin slideboxEnd($extraTransform: null) {
63
- @at-root :not([dir=rtl]) & {
64
- @include slideboxRight($extraTransform);
65
- }
66
- @at-root [dir=rtl] & {
67
- @include slideboxLeft($extraTransform);
68
- }
69
- }
70
-
71
-
72
-
73
- @mixin slideboxToStartAnimation() {
74
- @at-root :not([dir=rtl]) & {
75
- animation-name: slideboxToLeft;
76
- }
77
- @at-root [dir=rtl] & {
78
- animation-name: slideboxToRight;
79
- }
80
- }
81
-
82
- @mixin slideboxToEndAnimation() {
83
- @at-root :not([dir=rtl]) & {
84
- animation-name: slideboxToRight;
85
- }
86
- @at-root [dir=rtl] & {
87
- animation-name: slideboxToLeft;
88
- }
89
- }
90
-
91
- input[type=checkbox].#{$slideboxClassPrefix}slidebox {
92
- -webkit-appearance: none !important;
93
- -moz-appearance: none !important;
94
- -ms-appearance: none !important;
95
- -o-appearance: none !important;
96
- appearance: none !important;
97
- height: auto;
98
- width: auto;
99
- line-height: 0px;
100
- position: relative;
101
- color: $slideboxColorDefaultColor;
102
- outline: 0 !important;
103
- cursor: pointer;
104
- padding: 0 #{$spacing / 2};
105
- font-size: 1em;
106
- transform-origin: center center;
107
-
108
- &:focus::after {
109
- outline: auto 5px -webkit-focus-ring-color;
110
- }
111
-
112
- &::before {
113
- direction: ltr;
114
- position: absolute;
115
- content: '\f111\f111\f111\f111\f111\f111\f111';
116
- font-weight: 900;
117
- font-family: 'Font Awesome 5 Free';
118
- display: block;
119
- letter-spacing: -$spacing;
120
- margin-left: $spacing * 0.5;
121
- left: 50%;
122
- top: 50%;
123
- transform-origin: center center;
124
- -webkit-transform: translate(-50%, -50%) scale(0.8);
125
- transform: translate(-50%, -50%) scale(0.8);
126
- width: #{$spacing * 4};
127
- }
128
-
129
- &::after {
130
- line-height: 1em;
131
- position: relative;
132
- content: '\f111';
133
- font-weight: 900;
134
- padding: #{$spacing / 2};
135
- font-family: 'Font Awesome 5 Free';
136
- display: block;
137
- transform-origin: center center;
138
- animation-duration: 0.2s;
139
- animation-timing-function: cubic-bezier(0.68, -0.6, 0.32, 1.6);
140
- animation-fill-mode: forwards;
141
- filter: $slideboxShadowFilter;
142
- }
143
-
144
- &::before, &::after {
145
- transition: color 0.2s ease-in-out;
146
- }
147
-
148
- &:not(.inverted) {
149
- &::after {
150
- @include slideboxToEndAnimation;
151
- }
152
-
153
- &.dark {
154
- @include dark-colors;
155
- @include dark-filters;
156
- }
157
-
158
- &.light {
159
- @include light-colors;
160
- @include light-filters;
161
- }
162
-
163
- @if (lightness($slideboxColorDefaultColor) > 40) {
164
- @include light-colors;
165
- @include light-filters;
166
- } @else {
167
- @include dark-colors;
168
- @include dark-filters;
169
- }
170
-
171
- &:checked {
172
- &::before, &::after {
173
- color: inherit;
174
- }
175
-
176
- &::after {
177
- @include slideboxToStartAnimation;
178
- }
179
- }
180
-
181
- &:active {
182
- &:checked::after {
183
- @include slideboxStart(scale(1.1) !important);
184
- }
185
-
186
- &:not(:checked)::after {
187
- @include slideboxEnd(scale(1.1) !important);
188
- }
189
- }
190
- }
191
-
192
-
193
- &.inverted {
194
- &::before, &::after {
195
- color: inherit;
196
- }
197
-
198
- &::after {
199
- @include slideboxToStartAnimation;
200
- }
201
-
202
- &.dark {
203
- @include dark-filters;
204
- }
205
-
206
- &.light {
207
- @include light-filters;
208
- }
209
-
210
- @if (lightness($slideboxColorDefaultColor) > 40) {
211
- @include light-filters;
212
- } @else {
213
- @include dark-filters;
214
- }
215
-
216
- &:checked {
217
- &::after {
218
- @include slideboxToEndAnimation;
219
- }
220
-
221
- &.dark {
222
- @include dark-colors;
223
- }
224
-
225
- &.light {
226
- @include light-colors;
227
- }
228
-
229
- @if (lightness($slideboxColorDefaultColor) > 40) {
230
- @include light-colors;
231
- } @else {
232
- @include dark-colors;
233
- }
234
-
235
- }
236
-
237
- &:active {
238
- &:checked::after {
239
- @include slideboxEnd(scale(1.1) !important);
240
- }
241
-
242
- &:not(:checked)::after {
243
- @include slideboxStart(scale(1.1) !important);
244
- }
245
- }
246
- }
247
-
248
- }
249
-
250
- @keyframes slideboxToLeft {
251
- from {
252
- @include slideboxRight;
253
- }
254
- to {
255
- @include slideboxLeft;
256
- }
257
- }
258
-
259
- @keyframes slideboxToRight {
260
- from {
261
- @include slideboxLeft;
262
- }
263
- to {
264
- @include slideboxRight;
265
- }
266
- }
1
+ .slidebox {
2
+ --_container-width-ratio: 2;
3
+ --_thumb-spacing-ratio: .33;
4
+ --_deform: .1;
5
+ --_duration: 200ms;
6
+ --_easing-function: ease-in-out;
7
+ --_track: Field;
8
+ --_border: ButtonBorder;
9
+ --_off: FieldText;
10
+ --_on: light-dark(#0b75ff, SelectedItem);
11
+ appearance: none;
12
+ -webkit-appearance: none;
13
+ box-sizing: border-box;
14
+ display: inline-flex;
15
+ align-items: center;
16
+ justify-content: center;
17
+ width: calc(1em * var(--_container-width-ratio));
18
+ height: 1em;
19
+ font-size: 54px;
20
+ padding: 0;
21
+ border: 1px solid var(--_border);
22
+ border-radius: 100vw;
23
+ background: var(--_track);
24
+ cursor: pointer;
25
+ }
26
+ @supports (color: AccentColor) {
27
+ .slidebox { --_on: AccentColor; }
28
+ }
29
+ .slidebox::after {
30
+ --_start: 0; --_end: 1;
31
+ content: "";
32
+ display: block;
33
+ flex: 1 1 auto;
34
+ min-width: 0;
35
+ width: calc((1 - var(--_thumb-spacing-ratio)) * 1em);
36
+ height: calc((1 - var(--_thumb-spacing-ratio)) * 1em);
37
+ margin-block: calc(var(--_thumb-spacing-ratio) * .5em);
38
+ margin-inline-start: calc((1em * var(--_container-width-ratio) - 1em) * var(--_start) + var(--_thumb-spacing-ratio) * .5em);
39
+ margin-inline-end: calc((1em * var(--_container-width-ratio) - 1em) * var(--_end) + var(--_thumb-spacing-ratio) * .5em);
40
+ border-radius: inherit;
41
+ background: var(--_off);
42
+ transition: background var(--_duration) var(--_easing-function), margin-inline-start var(--_duration) var(--_easing-function), margin-inline-end var(--_duration) var(--_easing-function);
43
+ transition-delay: 0s, 0s, calc(var(--_duration) * var(--_deform));
44
+ }
45
+ .slidebox:checked::after {
46
+ --_start: 1; --_end: 0;
47
+ background: var(--_on);
48
+ transition-delay: 0s, calc(var(--_duration) * var(--_deform)), 0s;
49
+ }
50
+ .slidebox:not(:checked):active::after { --_end: calc(1 - var(--_deform)); }
51
+ .slidebox:checked:active::after { --_start: calc(1 - var(--_deform)); }
52
+ .slidebox:disabled { cursor: not-allowed; opacity: .5; }
53
+ @media (forced-colors: active) {
54
+ .slidebox { --_track: Field; --_border: ButtonBorder; --_off: FieldText; --_on: Highlight; }
55
+ }
56
+ @media (prefers-reduced-motion: reduce) {
57
+ .slidebox::after { transition-duration: .01ms; transition-delay: 0ms; }
58
+ }
@@ -1 +0,0 @@
1
- {"version":3,"sourceRoot":"","sources":["../../scss/slidebox.scss"],"names":[],"mappings":";AA0FA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,OApG0B;EAqG1B;EACA;EACA;EACA;EACA;;AAEA;EACE;;AAGF;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;AAGF;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,QAvImB;;AA0IrB;EACE;;AA9DO;EACP;;;AAEO;EACP;;;AAvEF;EACE;;AAGF;EACE;;AAXF;EACE;;AAqBF;EACE;;AAGF;EACE;;AAXF;EACE;;AAKF;EACE;;AAGF;EACE;;AAXF;EACE;;AAiJE;EACE;;AAnGG;EACP;;;AAEO;EACP;;;AAxBO;EANT;EACA;;;AAQS;EAfT;EACA;;;AAoBS;EArBT;EACA;;;AAuBS;EAlBT;EACA;;;AAiJE;EACE;;AAzHK;EACP;;;AAEO;EACP;;;AApEF;EACE;;AAeF;EACE;;AADF;EACE;;AAwDO;EACP;;;AAEO;EACP;;;AAvEF;EACE;;AAGF;EACE;;AAWF;EACE;;AAGF;EACE;;AALF;EACE;;AAGF;EACE;;AA0BO;EArBT;EACA;;;AAuBS;EAlBT;EACA;;;AAKS;EANT;EACA;;;AAQS;EAfT;EACA;;;AA+MF;EACE;IAjNA;IACA;;EAmNA;IA9MA;IACA;;;AAkNF;EACE;IApNA;IACA;;EAsNA;IA7NA;IACA","file":"slidebox.css"}
@@ -1,41 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport"
6
- content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
7
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
8
- <title>@monabbous/slidebox Simple Example</title>
9
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css"
10
- integrity="sha512-+4zCK9k+qNFUR5X+cKL9EIR+ZOhtIloNl9GIKS57V1MyNsYpYcUrUeQc9vNfzsWfV28IaLL3i96P9sdNyeRssA=="
11
- crossorigin="anonymous"/>
12
- <link rel="stylesheet" href="https://unpkg.com/@monabbous/slidebox@0.0.6/dist/css/slidebox.css"/>
13
- <style>
14
- body {
15
- font-family: "Source Code Pro", "SF Mono", Monaco, Inconsolata, "Fira Mono", "Droid Sans Mono", monospace, monospace;
16
- }
17
- </style>
18
- </head>
19
- <body>
20
- <h2>Default Slidebox</h2>
21
- <div style="font-size: 2rem">
22
- <input type="checkbox" class="slidebox">
23
- <input type="checkbox" checked class="slidebox">
24
- </div>
25
- <h2>Custom Dark Color Slidebox</h2>
26
- <div style="font-size: 2rem">
27
- <input style="color:#040491" type="checkbox" class="slidebox dark">
28
- <input style="color:#040491" type="checkbox" checked class="slidebox dark">
29
- </div>
30
- <h2>Custom Light Color Slidebox</h2>
31
- <div style="font-size: 2rem">
32
- <input style="color:#a8a8ff" type="checkbox" class="slidebox light">
33
- <input style="color:#a8a8ff" type="checkbox" checked class="slidebox light">
34
- </div>
35
- <h2>Inverted Slidebox</h2>
36
- <div style="font-size: 2rem">
37
- <input type="checkbox" class="slidebox inverted">
38
- <input type="checkbox" checked class="slidebox inverted">
39
- </div>
40
- </body>
41
- </html>