Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
128 commits
Select commit Hold shift + click to select a range
54cab76
feat: enable in/valid state for switch
michaelmkraus Aug 28, 2025
06fc979
feat(switch): unify validation styling and messages
michaelmkraus Sep 4, 2025
c93b20e
Merge branch 'main' into 851-switch-stable
michaelmkraus Sep 4, 2025
bddb8fb
feat(switch): configurable label position
michaelmkraus Sep 8, 2025
c7c72d6
Merge remote-tracking branch 'origin/851-switch-stable' into 851-swit…
michaelmkraus Sep 8, 2025
275b0f0
feat(switch): add accent styling, same visual appearance as valid state
michaelmkraus Sep 8, 2025
2a9efd4
feat(switch): a11y and validity style improvements
michaelmkraus Sep 8, 2025
8c66eb9
Merge branch 'main' into 851-switch-stable
michaelmkraus Sep 8, 2025
63ffa8e
feat(switch): fix linting errors
michaelmkraus Sep 8, 2025
c8b82ab
Merge remote-tracking branch 'origin/851-switch-stable' into 851-swit…
michaelmkraus Sep 8, 2025
971d832
feat(switch): simplify SCSS mixin and remove unused imports
michaelmkraus Sep 8, 2025
d6b078f
feat(switch): removed aria-describedby
michaelmkraus Sep 9, 2025
316cb67
auto update snapshots (#4944)
github-actions[bot] Sep 9, 2025
7283c8a
test: updated snapshots
michaelmkraus Sep 9, 2025
768828a
Merge remote-tracking branch 'origin/851-switch-stable' into 851-swit…
michaelmkraus Sep 9, 2025
195181a
feat(switch): adapt label color for valid and invalid state
michaelmkraus Sep 9, 2025
1aad439
feat(switch): remove aria-checked because it is not valid for inputs
michaelmkraus Sep 9, 2025
c442b26
feat(switch): update switch snapshots
michaelmkraus Sep 9, 2025
0c573e6
feat(switch): remove emphasis property from switch
michaelmkraus Sep 11, 2025
a6f7441
Merge branch 'main' into 851-switch-stable
michaelmkraus Sep 11, 2025
85b346a
feat(switch): update switch snapshots
michaelmkraus Sep 11, 2025
9a0f9c2
Merge remote-tracking branch 'origin/851-switch-stable' into 851-swit…
michaelmkraus Sep 11, 2025
c862521
feat(switch): remove example with emphasis from showcase
michaelmkraus Sep 11, 2025
77ea68d
fix(docs): correct font path reference in migration documentation
michaelmkraus Sep 11, 2025
0582f3b
feat(switch): update switch snapshots
michaelmkraus Sep 11, 2025
82d09f2
feat(switch): update switch snapshots
michaelmkraus Sep 11, 2025
fbef1a0
feat(switch): update switch stencil-shocase snapshots
michaelmkraus Sep 11, 2025
b9ba796
feat(switch): update switch showcase snapshots
michaelmkraus Sep 11, 2025
308f117
feat(switch): update switch angular and react showcase snapshots
michaelmkraus Sep 11, 2025
8a60d90
test(switch): restore baseline visual snapshots from main
michaelmkraus Sep 11, 2025
d1dbdfe
fix(switch): ensure snapshot regeneration triggers on showcase test f…
michaelmkraus Sep 12, 2025
415dd32
Merge branch 'main' into 851-switch-stable
michaelmkraus Sep 12, 2025
91cea13
auto update snapshots (#4961)
github-actions[bot] Sep 12, 2025
9d2b42b
test: updated snapshots
michaelmkraus Sep 12, 2025
69cf19b
Merge remote-tracking branch 'origin/851-switch-stable' into 851-swit…
michaelmkraus Sep 12, 2025
8eb2870
fix(switch): add missing regenerate snapshot scripts to angular and v…
michaelmkraus Sep 12, 2025
a610237
test: updated snapshots
michaelmkraus Sep 12, 2025
e287d3f
fix(switch): resolve snapshot regeneration for component tests
michaelmkraus Sep 12, 2025
38f894a
Merge branch 'main' into 851-switch-stable
michaelmkraus Sep 12, 2025
4592e19
Merge branch 'main' into 851-switch-stable
michaelmkraus Sep 15, 2025
b152d92
Merge branch 'main' into 851-switch-stable
mfranzke Sep 15, 2025
217980b
fix(switch): remove unnecessary selector for switch label
michaelmkraus Sep 15, 2025
a0d4440
Merge remote-tracking branch 'origin/851-switch-stable' into 851-swit…
michaelmkraus Sep 15, 2025
e8fa131
feat(switch): add aria attribute describedby to input of switch
michaelmkraus Sep 15, 2025
a8a9e88
refactor(switch): type ref as HTMLInputElement instead of any
michaelmkraus Sep 15, 2025
b7fd480
feat(switch): simplify validity mixin for switch
michaelmkraus Sep 15, 2025
a420631
Merge branch 'main' into 851-switch-stable
michaelmkraus Sep 15, 2025
29521dd
fix(switch): use any type to prevent typescript conflicts at compilin…
michaelmkraus Sep 15, 2025
986508f
Merge remote-tracking branch 'origin/851-switch-stable' into 851-swit…
michaelmkraus Sep 15, 2025
d5c1545
test: updated snapshots
michaelmkraus Sep 15, 2025
26d3b6d
test: updated snapshots
michaelmkraus Sep 15, 2025
0c988f5
feat(switch): hand over valid and invalid message for angular and vue
michaelmkraus Sep 15, 2025
85f11b9
test: updated snapshots
michaelmkraus Sep 15, 2025
87b3ab7
test: updated snapshots
michaelmkraus Sep 15, 2025
e5333ca
chore(): adapt pipeline to handle has-failure correctly
michaelmkraus Sep 15, 2025
099c5c2
chore(): readd always() to condition of commit-regenerate-snapshot
michaelmkraus Sep 15, 2025
f8c8a9f
Merge branch 'main' into 851-switch-stable
michaelmkraus Sep 15, 2025
4ad160e
auto update snapshots (#4973)
github-actions[bot] Sep 15, 2025
4ca6b3c
Merge branch 'main' into 851-switch-stable
michaelmkraus Sep 16, 2025
8bc8e6e
chore(): increase threshold for snapshot validation
michaelmkraus Sep 16, 2025
843ecb8
auto update snapshots (#4977)
github-actions[bot] Sep 16, 2025
7e1f02f
chore(): increase threshold for react snapshot
michaelmkraus Sep 16, 2025
2137748
Merge remote-tracking branch 'origin/851-switch-stable' into 851-swit…
michaelmkraus Sep 16, 2025
114e4ab
Merge branch 'main' into 851-switch-stable
michaelmkraus Sep 16, 2025
c11a0b8
chore(): increase threshold for angular snapshot
michaelmkraus Sep 16, 2025
d963dd9
Merge remote-tracking branch 'origin/851-switch-stable' into 851-swit…
michaelmkraus Sep 16, 2025
e6d9ca3
Merge branch 'main' into 851-switch-stable
michaelmkraus Sep 17, 2025
678f9f8
Merge branch 'main' into 851-switch-stable
michaelmkraus Sep 17, 2025
0e6a81c
Merge branch 'main' into 851-switch-stable
michaelmkraus Sep 17, 2025
223fa1a
Merge branch 'main' into 851-switch-stable
michaelmkraus Sep 18, 2025
c9f7779
feat(): add leading and trailing icon for visual aid
michaelmkraus Sep 18, 2025
667f69f
feat(): remove transition from icons when switching
michaelmkraus Sep 18, 2025
e2dd8c2
feat(): change label color for invalid state to correct value
michaelmkraus Sep 18, 2025
5b1fba8
feat(): add example for showMessage property
michaelmkraus Sep 18, 2025
b68ef66
auto update snapshots (#5005)
github-actions[bot] Sep 18, 2025
5e0c8bf
feat(switch): adapt hover and pressed color
michaelmkraus Sep 19, 2025
eddf837
Merge remote-tracking branch 'origin/851-switch-stable' into 851-swit…
michaelmkraus Sep 19, 2025
99d984f
Merge branch 'main' into 851-switch-stable
michaelmkraus Sep 19, 2025
93e24cc
feat(switch): wrap long labels correctly
michaelmkraus Sep 19, 2025
e4eae00
Merge remote-tracking branch 'origin/851-switch-stable' into 851-swit…
michaelmkraus Sep 19, 2025
b5066fc
Merge branch 'main' into 851-switch-stable
michaelmkraus Sep 19, 2025
f17386c
Merge branch 'main' into 851-switch-stable
michaelmkraus Sep 22, 2025
4fffe29
chore(switch): revert pipeline changes
michaelmkraus Sep 22, 2025
46e1608
Merge remote-tracking branch 'origin/851-switch-stable' into 851-swit…
michaelmkraus Sep 22, 2025
c6e04a3
chore(switch): revert unused scripts
michaelmkraus Sep 22, 2025
6238862
chore(switch): revert unused scripts
michaelmkraus Sep 22, 2025
9f7e800
auto update snapshots (#5017)
github-actions[bot] Sep 22, 2025
f50011d
chore(switch): remove unnecessary comments
michaelmkraus Sep 22, 2025
61e849c
Merge remote-tracking branch 'origin/851-switch-stable' into 851-swit…
michaelmkraus Sep 22, 2025
03b9666
auto update snapshots (#5018)
github-actions[bot] Sep 22, 2025
72af3da
feat(switch): adapt hover-color when no more hovering and adapt messa…
michaelmkraus Sep 23, 2025
97176af
feat(switch): show default icon for messages
michaelmkraus Sep 23, 2025
d99cf60
Merge branch 'main' into 851-switch-stable
michaelmkraus Sep 23, 2025
b78d50d
feat(switch): show default icon for messages
michaelmkraus Sep 23, 2025
36cb89f
Merge remote-tracking branch 'origin/851-switch-stable' into 851-swit…
michaelmkraus Sep 23, 2025
dffa666
chore: add db-theme, db-theme-fonts and db-theme-icons to package.jso…
michaelmkraus Sep 23, 2025
9bf2b2b
chore: synchronize package-lock
michaelmkraus Sep 23, 2025
d3706a1
auto update snapshots (#5033)
github-actions[bot] Sep 23, 2025
dd000db
chore: adapt label of show message showcase
michaelmkraus Sep 23, 2025
c9e5aed
Merge remote-tracking branch 'origin/851-switch-stable' into 851-swit…
michaelmkraus Sep 23, 2025
7d38381
auto update snapshots (#5035)
github-actions[bot] Sep 23, 2025
d2d52ad
feat(switch): remove hover-color of switch when leaving control
michaelmkraus Sep 24, 2025
9ac3e2e
Merge remote-tracking branch 'origin/main' into 851-switch-stable
michaelmkraus Sep 24, 2025
0f94bb5
Merge branch 'main' into 851-switch-stable
michaelmkraus Sep 24, 2025
74ac47f
feat(switch): pass showMessage for vue and angular
michaelmkraus Sep 24, 2025
439d041
Merge remote-tracking branch 'origin/851-switch-stable' into 851-swit…
michaelmkraus Sep 24, 2025
daecd8f
Merge branch 'main' into 851-switch-stable
michaelmkraus Sep 24, 2025
54c6d22
Merge branch 'main' into 851-switch-stable
michaelmkraus Sep 24, 2025
ce71a8c
Merge branch 'main' into 851-switch-stable
michaelmkraus Sep 24, 2025
e511c7d
chore(switch): remove accent showcase
michaelmkraus Sep 25, 2025
b81a9e6
Merge remote-tracking branch 'origin/851-switch-stable' into 851-swit…
michaelmkraus Sep 25, 2025
7d6e57c
Merge branch 'main' into 851-switch-stable
michaelmkraus Sep 25, 2025
a01c3c5
chore(switch): set background when not checked but focused
michaelmkraus Sep 25, 2025
71316ee
auto update snapshots (#5061)
github-actions[bot] Sep 25, 2025
e00b00c
Merge branch 'main' into 851-switch-stable
michaelmkraus Sep 25, 2025
e62fbbe
chore(switch): add fonts and icons dependencies to patternhub
michaelmkraus Sep 26, 2025
77be3aa
auto update snapshots (#5071)
github-actions[bot] Sep 26, 2025
9466958
feat(switch): adapt pressed unchecked color
michaelmkraus Sep 26, 2025
9679c1a
auto update snapshots (#5072)
github-actions[bot] Sep 26, 2025
c339219
feat(switch): show asterisk behind label if switch is required
michaelmkraus Sep 30, 2025
24b9ea7
fix(switch): adapt margin of small labels for angular and vue
michaelmkraus Sep 30, 2025
3228821
Merge branch 'main' into 851-switch-stable
michaelmkraus Sep 30, 2025
203c1d3
Merge branch 'main' into 851-switch-stable
michaelmkraus Sep 30, 2025
6580617
auto update snapshots (#5099)
github-actions[bot] Sep 30, 2025
37265c7
feat(switch): do not add label-position attribute if showLabel is
michaelmkraus Sep 30, 2025
b8e5c05
Merge remote-tracking branch 'origin/851-switch-stable' into 851-swit…
michaelmkraus Sep 30, 2025
806bda9
auto update snapshots (#5102)
github-actions[bot] Sep 30, 2025
7e5d88c
Merge branch 'main' into 851-switch-stable
michaelmkraus Sep 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 12 additions & 4 deletions packages/components/src/components/switch/model.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import {
ChangeEventProps,
ChangeEventState,
EmphasisProps,
FocusEventProps,
FocusEventState,
FormCheckProps,
FormMessageProps,
FormProps,
FormState,
FromValidState,
GlobalProps,
GlobalState,
IconLeadingProps,
IconProps,
IconTrailingProps,
LabelPositionProps,
SizeProps
} from '../../shared/model';

Expand All @@ -20,6 +22,10 @@ export type DBSwitchDefaultProps = {
* Add additional icons to indicate active/inactive state.
*/
visualAid?: boolean | string;
/**
* Use accent styling (same visual appearance as valid state).
*/
accent?: boolean | string;
};

export type DBSwitchProps = DBSwitchDefaultProps &
Expand All @@ -28,16 +34,18 @@ export type DBSwitchProps = DBSwitchDefaultProps &
FocusEventProps<HTMLInputElement> &
FormProps &
FormCheckProps &
EmphasisProps &
FormMessageProps &
SizeProps &
IconProps &
IconTrailingProps &
IconLeadingProps;
IconLeadingProps &
LabelPositionProps;

export type DBSwitchDefaultState = {};

export type DBSwitchState = DBSwitchDefaultState &
GlobalState &
ChangeEventState<HTMLInputElement> &
FocusEventState<HTMLInputElement> &
FormState;
FormState &
FromValidState;
130 changes: 124 additions & 6 deletions packages/components/src/components/switch/switch.lite.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
onMount,
onUpdate,
Show,
useDefaultProps,
useMetadata,
Expand All @@ -8,18 +9,29 @@ import {
useTarget
} from '@builder.io/mitosis';

import {
DEFAULT_INVALID_MESSAGE,
DEFAULT_INVALID_MESSAGE_ID_SUFFIX,
DEFAULT_MESSAGE_ID_SUFFIX,
DEFAULT_VALID_MESSAGE,
DEFAULT_VALID_MESSAGE_ID_SUFFIX
} from '../../shared/constants';
import { ChangeEvent, InteractionEvent } from '../../shared/model';
import {
cls,
delay,
getBoolean,
getBooleanAsString,
getHideProp,
hasVoiceOver,
stringPropVisible,
uuid
} from '../../utils';
import {
handleFrameworkEventAngular,
handleFrameworkEventVue
} from '../../utils/form-components';
import DBInfotext from '../infotext/infotext.lite';
import { DBSwitchProps, DBSwitchState } from './model';

useMetadata({
Expand All @@ -30,14 +42,65 @@ useMetadata({
}
}
});
useDefaultProps<DBSwitchProps>({});
useDefaultProps<DBSwitchProps>({
labelPosition: 'trailing'
});

export default function DBSwitch(props: DBSwitchProps) {
// This is used as forwardRef
const _ref = useRef<HTMLInputElement | any>(null);
// jscpd:ignore-start
const state = useStore<DBSwitchState>({
_id: undefined,
_messageId: undefined as string | undefined,
_validMessageId: undefined as string | undefined,
_invalidMessageId: undefined as string | undefined,
_invalidMessage: undefined as string | undefined,
_descByIds: '' as string,
_voiceOverFallback: '' as string,

hasValidState: () => {
return !!(props.validMessage ?? props.validation === 'valid');
},
handleValidation: () => {
if (!_ref?.validity?.valid || props.validation === 'invalid') {
state._descByIds = state._invalidMessageId!;
state._invalidMessage =
props.invalidMessage ||
_ref?.validationMessage ||
DEFAULT_INVALID_MESSAGE;
if (hasVoiceOver()) {
state._voiceOverFallback =
state._invalidMessage || DEFAULT_INVALID_MESSAGE;
delay(() => {
state._voiceOverFallback = '';
}, 1000);
}
return;
}
if (
state.hasValidState() &&
_ref?.validity?.valid &&
props.required
) {
state._descByIds = state._validMessageId!;
if (hasVoiceOver()) {
state._voiceOverFallback =
props.validMessage ?? DEFAULT_VALID_MESSAGE;
delay(() => {
state._voiceOverFallback = '';
}, 1000);
}
return;
}

if (stringPropVisible(props.message, props.showMessage)) {
state._descByIds = state._messageId!;
return;
}

state._descByIds = '';
},
handleChange: (event: ChangeEvent<HTMLInputElement>) => {
useTarget({
angular: () =>
Expand All @@ -49,6 +112,7 @@ export default function DBSwitch(props: DBSwitchProps) {
}
}
});
state.handleValidation();
},
handleBlur: (event: InteractionEvent<HTMLInputElement>) => {
if (props.onBlur) {
Expand All @@ -64,18 +128,40 @@ export default function DBSwitch(props: DBSwitchProps) {

onMount(() => {
state._id = props.id ?? `switch-${uuid()}`;
state._messageId = `${state._id}${DEFAULT_MESSAGE_ID_SUFFIX}`;
state._validMessageId = `${state._id}${DEFAULT_VALID_MESSAGE_ID_SUFFIX}`;
state._invalidMessageId = `${state._id}${DEFAULT_INVALID_MESSAGE_ID_SUFFIX}`;
state.handleValidation();
});

onUpdate(() => {
state.handleValidation();
}, [
props.validation,
props.required,
props.message,
props.showMessage,
props.validMessage,
props.invalidMessage,
props.checked
]);

// jscpd:ignore-end

return (
<label
data-visual-aid={getBooleanAsString(props.visualAid)}
data-size={props.size}
data-hide-label={getHideProp(props.showLabel)}
data-emphasis={props.emphasis}
htmlFor={state._id}
data-label-position={
getHideProp(props.showLabel) === 'true'
? undefined
: props.labelPosition
}
data-accent={getBooleanAsString(props.accent)}
data-hide-asterisk={getHideProp(props.showRequiredAsterisk)}
data-custom-validity={props.validation}
class={cls('db-switch', props.className)}>
<input
id={state._id}
Expand All @@ -85,8 +171,10 @@ export default function DBSwitch(props: DBSwitchProps) {
checked={getBoolean(props.checked, 'checked')}
value={props.value}
disabled={getBoolean(props.disabled, 'disabled')}
aria-invalid={props.validation === 'invalid'}
data-custom-validity={props.validation}
aria-invalid={
props.validation === 'invalid' ? 'true' : undefined
}
aria-describedby={state._descByIds || undefined}
name={props.name}
required={getBoolean(props.required, 'required')}
data-aid-icon={props.iconLeading ?? props.icon}
Expand All @@ -101,9 +189,39 @@ export default function DBSwitch(props: DBSwitchProps) {
state.handleFocus(event)
}
/>
<Show when={props.label} else={props.children}>
{props.label}
<span class="db-switch-label">
<Show when={props.label} else={props.children}>
{props.label}
</Show>
</span>
<Show when={stringPropVisible(props.message, props.showMessage)}>
<DBInfotext
id={state._messageId}
size="small"
icon={props.messageIcon}
semantic="adaptive">
{props.message}
</DBInfotext>
</Show>
<Show when={state.hasValidState()}>
<DBInfotext
id={state._validMessageId}
size="small"
semantic="successful">
{props.validMessage ?? DEFAULT_VALID_MESSAGE}
</DBInfotext>
</Show>
<DBInfotext
id={state._invalidMessageId}
size="small"
semantic="critical">
{state._invalidMessage ??
props.invalidMessage ??
DEFAULT_INVALID_MESSAGE}
</DBInfotext>
<span data-visually-hidden="true" role="status">
{state._voiceOverFallback}
</span>
</label>
);
}
Loading
Loading