Skip to content

Commit

Permalink
fixup! Feat(web-react): Introduce UNSTABLE_Toggle component #DS-1346
Browse files Browse the repository at this point in the history
  • Loading branch information
curdaj committed Jul 16, 2024
1 parent 017fe65 commit 7cd70e1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ const _UNSTABLE_Toggle = (props: SpiritToggleProps, ref: ForwardedRef<HTMLInputE
id,
isDisabled,
isChecked,
isRequired,
label,
helperText,
onChange,
onChange = () => {},
validationState,
validationText,
...restProps
Expand Down Expand Up @@ -55,8 +56,8 @@ const _UNSTABLE_Toggle = (props: SpiritToggleProps, ref: ForwardedRef<HTMLInputE
className={classProps.input}
disabled={isDisabled}
checked={isChecked}
required={isRequired}
onChange={onChange}
name="default"
ref={ref}
/>
</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,21 @@ export interface ToggleStyles<T> {
}

export function useToggleStyleProps(props: SpiritToggleProps): ToggleStyles<SpiritToggleProps> {
const { isRequired = false, isFluid = false, isDisabled, isLabelHidden = false, validationState } = props;
const {
isRequired = false,
isFluid = false,
isDisabled,
isLabelHidden = false,
validationState,
...restProps
} = props;

const toggleClass = useClassNamePrefix('UNSTABLE_Toggle');
const toggleHiddenLabelClass = `${toggleClass}--hiddenLabel`;
const toggleFluidClass = `${toggleClass}--fluid`;
const toggleDisabledClass = `${toggleClass}--disabled`;
const toggleTextClass = `${toggleClass}__text`;
const toggleLabelClass = `${toggleClass}__label`;
const toggleHiddenLabelClass = `${toggleLabelClass}--hidden`;
const toggleValidationClass = `${toggleClass}--${validationState}`;
const toggleRequiredClass = `${toggleLabelClass}--required`;
const toggleInputClass = `${toggleClass}__input`;
Expand All @@ -47,6 +54,6 @@ export function useToggleStyleProps(props: SpiritToggleProps): ToggleStyles<Spir
input: toggleInputClass,
validationText: toggleValidationTextClass,
},
props,
props: restProps,
};
}
2 changes: 2 additions & 0 deletions packages/web-react/src/types/toggle.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ChangeEvent } from 'react';
import { LabelProps } from './label';
import {
ChildrenProps,
Expand Down Expand Up @@ -27,6 +28,7 @@ export interface ToggleProps
isLabelHidden?: boolean;
label: string;
validationText?: ValidationTextType;
onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
}

export interface SpiritToggleProps extends ToggleProps {}

0 comments on commit 7cd70e1

Please sign in to comment.