Skip to content

Commit 29531db

Browse files
authored
Merge pull request #17492 from craftcms/feature/cms-17474-lightswitch-contrast
Lightswitch tweaks
2 parents 5a9b5a4 + 510ed0e commit 29531db

7 files changed

Lines changed: 128 additions & 24 deletions

File tree

CHANGELOG-WIP.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
### Accessibility
2626
- The Crop tool within the Image Editor is now screen reader and keyboard accessible. ([#17358](https://github.com/craftcms/cms/pull/17358))
27+
- Lightswitches now have a checkmark icon when turned on, and improved styling. ([#17492](https://github.com/craftcms/cms/pull/17492))
2728

2829
### Administration
2930
- Added the “Content Block” field type. ([#17424](https://github.com/craftcms/cms/pull/17424))

src/templates/tests/forms.twig

Lines changed: 75 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,29 +85,90 @@
8585
]
8686
}) }}
8787

88+
<hr/>
89+
<div>
90+
<h2 id="lightswitches">Lightswitches</h2>
91+
{{ forms.lightswitchField({
92+
label: 'Default'|t('app'),
93+
on: true,
94+
}) }}
95+
96+
{{ forms.lightswitchField({
97+
label: 'Small'|t('app'),
98+
small: true,
99+
on: true,
100+
}) }}
101+
102+
{{ forms.lightswitchField({
103+
label: 'Default'|t('app'),
104+
}) }}
105+
106+
{{ forms.lightswitchField({
107+
label: 'Small'|t('app'),
108+
small: true,
109+
}) }}
110+
111+
{{ forms.lightswitchField({
112+
label: 'Disabled'|t('app'),
113+
disabled: true,
114+
}) }}
115+
116+
{{ forms.lightswitchField({
117+
label: 'Indeterminate'|t('app'),
118+
indeterminate: true,
119+
}) }}
120+
121+
{{ forms.lightswitchField({
122+
label: 'Indeterminate (small)'|t('app'),
123+
indeterminate: true,
124+
small: true,
125+
}) }}
126+
127+
{{ forms.lightswitchField({
128+
label: 'With Labels'|t('app'),
129+
on: true,
130+
onLabel: 'On',
131+
offLabel: 'Off'
132+
}) }}
133+
134+
<div class="pane">
135+
{{ forms.lightswitchField({
136+
label: 'With Background'|t('app'),
137+
on: true,
138+
}) }}
139+
{{ forms.lightswitchField({
140+
label: 'With Background'|t('app'),
141+
on: false,
142+
}) }}
143+
{{ forms.lightswitchField({
144+
label: 'Disabled'|t('app'),
145+
disabled: true,
146+
}) }}
147+
</div>
148+
<hr/>
88149
{% endblock %}
89150

90151
{% js %}
91152
var $content = $('#content');
92153

93154
$content.append(Craft.ui.createCheckboxSelectField({
94-
label: 'Checkbox select with “All” option (JS)',
95-
options: [
96-
{ value: 'one', label: 'One' },
97-
{ value: 'two', label: 'Two' },
98-
{ value: 'three', label: 'Three' },
99-
],
100-
showAllOption: true,
155+
label: 'Checkbox select with “All” option (JS)',
156+
options: [
157+
{value: 'one', label: 'One'},
158+
{value: 'two', label: 'Two'},
159+
{value: 'three', label: 'Three'},
160+
],
161+
showAllOption: true,
101162
}));
102163

103164
$content.append(Craft.ui.createCheckboxSelectField({
104-
label: 'Checkbox select without “All” option (JS)',
105-
options: [
106-
{ value: 'one', label: 'One' },
107-
{ value: 'two', label: 'Two' },
108-
{ value: 'three', label: 'Three' },
109-
],
110-
showAllOption: false,
165+
label: 'Checkbox select without “All” option (JS)',
166+
options: [
167+
{value: 'one', label: 'One'},
168+
{value: 'two', label: 'Two'},
169+
{value: 'three', label: 'Three'},
170+
],
171+
showAllOption: false,
111172
}));
112173
{% endjs %}
113174

src/web/assets/cp/dist/css/cp.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/web/assets/cp/dist/css/cp.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/web/assets/cp/src/css/_main.scss

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
@charset "UTF-8";
2-
@charset "UTF-8";
32
@use 'sass:color';
43
@use 'variables';
54
@use '@craftcms/sass/mixins';
@@ -2824,29 +2823,55 @@ div.btn.submit input {
28242823
}
28252824

28262825
.lightswitch {
2826+
// Ensures contrast with pane background is over 3:1
2827+
--_lightswitch-border-color: var(
2828+
--lightswitch-border-color,
2829+
hsl(from var(--input-border-color) h s l / 80%)
2830+
);
28272831
display: block;
28282832
position: relative;
28292833
border: none !important;
28302834
overflow: hidden;
28312835
cursor: pointer;
28322836
user-select: none;
2833-
background-image: linear-gradient(to right, var(--gray-400), var(--gray-400));
2837+
background-image: linear-gradient(to right, var(--gray-200), var(--gray-200));
28342838
transition: background-image linear 100ms;
2835-
box-shadow: inset 0 0 0 1px rgb(0 0 0 / 10%); // Ensures contrast with pane background is over 3:1
2839+
box-shadow: inset 0 0 0 1px var(--_lightswitch-border-color);
2840+
2841+
&[disabled] {
2842+
--_lightswitch-border-color: var(
2843+
--lightswitch-border-color-disabled,
2844+
hsl(from var(--input-border-color) h s l / 30%)
2845+
);
2846+
}
28362847

28372848
&.on {
2849+
--_lightswitch-border-color: oklch(
2850+
from var(--bg-enabled) calc(l - 0.1) c h
2851+
);
28382852
background-image: linear-gradient(
28392853
to right,
28402854
var(--bg-enabled),
28412855
var(--bg-enabled)
28422856
);
2857+
2858+
.lightswitch-container .handle::before {
2859+
background-color: var(--enabled-color);
2860+
mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 448 512'%3E%3C!--! Font Awesome Pro 6.7.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2024 Fonticons, Inc. --%3E%3Cpath d='M438.6 105.4c12.5 12.5 12.5 32.8 0 45.3l-256 256c-12.5 12.5-32.8 12.5-45.3 0l-128-128c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L160 338.7 393.4 105.4c12.5-12.5 32.8-12.5 45.3 0z'/%3E%3C/svg%3E%0A");
2861+
mask-repeat: no-repeat;
2862+
}
2863+
2864+
// Makes small icon a little darker to compensate for the size
2865+
&.small .lightswitch-container .handle::before {
2866+
background-color: hsl(from var(--enabled-color) h s calc(l - 20));
2867+
}
28432868
}
28442869

28452870
&.indeterminate {
28462871
background-image: linear-gradient(
28472872
to right,
2848-
var(--bg-enabled),
2849-
var(--gray-300)
2873+
var(--bg-enabled) 40%,
2874+
var(--gray-200) 60%
28502875
);
28512876
}
28522877

@@ -2858,7 +2883,17 @@ div.btn.submit input {
28582883
position: absolute;
28592884
inset-block-start: 2px;
28602885
background-color: var(--white);
2861-
box-shadow: 0 0 0 1px rgb(0 0 0 / 10%); // Ensures contrast with pane background is over 3:1
2886+
box-shadow: inset 0 0 0 1px var(--_lightswitch-border-color);
2887+
}
2888+
2889+
.handle::before {
2890+
content: '';
2891+
position: absolute;
2892+
inset-block-start: 50%;
2893+
inset-inline-start: 54%;
2894+
transform: translateX(-50%) translateY(-50%);
2895+
width: 12px;
2896+
height: 12px;
28622897
}
28632898
}
28642899

@@ -2896,6 +2931,11 @@ div.btn.submit input {
28962931
height: 14px;
28972932
inset-inline-start: calc(50% - 7px);
28982933
}
2934+
2935+
.handle::before {
2936+
width: 8px;
2937+
height: 8px;
2938+
}
28992939
}
29002940
}
29012941

src/web/assets/theme/dist/cp.css

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/web/assets/theme/dist/fe.css

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)