Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Align toggle styles with style guide #336

Merged
merged 9 commits into from
May 26, 2020
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
"polished": "3.5.1",
"react-svg": "11.0.16",
"suomifi-design-tokens": "0.8.0",
"suomifi-icons": "0.1.1",
"suomifi-icons": "0.1.2",
"uuid": "7.0.3"
},
"peerDependencies": {
Expand Down
134 changes: 81 additions & 53 deletions src/core/Form/Toggle/Toggle.baseStyles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,86 +8,114 @@ const svgPrefix = 'icon-toggle_svg__';
const iconWidth = '40px';
const iconHeight = '24px';

const focusOverrides = css`
position: absolute;
&:after {
border-radius: 14px;
right: -4px;
left: -4px;
}
`;

/* stylelint-disable no-descending-specificity */
export const baseStyles = withSuomifiTheme(
({ theme }: TokensAndTheme) => css`
${element({ theme })}
${font({ theme })('bodyText')}
background-color: ${theme.colors.whiteBase};
${element({ theme })}
${font({ theme })('bodyText')}
background-color: ${theme.colors.whiteBase};
padding-left: 50px;
position: relative;
display: inline-block;

& .fi-toggle_icon-container {
position: absolute;
margin-right: ${theme.spacing.insetL};
left: 0;
top: 0.1em;
}

& + .fi-toggle--with-button {
&:focus {
outline: 0;
${focus({ theme, noPseudo: true })}
& .fi-toggle_icon-container {
${focus({ theme, noPseudo: true })}
${focusOverrides}
}
}
&:focus:not(:focus-visible) {
outline: 0;
&:after {
content: none;
& .fi-toggle_icon-container {
&:after {
content: none;
}
}
}
}

& + .fi-toggle--with-input {
&:focus-within {
outline: 0;
${focus({ theme, noPseudo: true })}
& .fi-toggle_icon-container {
${focus({ theme, noPseudo: true })}
${focusOverrides}
}
}
&:focus-within:not(:focus-visible) {
outline: 0;
&:after {
content: none;
& .fi-toggle_icon-container {
&:after {
content: none;
}
}
}
}
& > .fi-toggle_input {
${element({ theme })}
${font({ theme })('bodyText')}
position: absolute;
width: ${iconWidth};
height: ${iconHeight};
opacity: 0;
z-index: -9999;
background-color: ${theme.colors.whiteBase};
}
& .fi-toggle_icon {
width: ${iconWidth};
height: ${iconHeight};
margin-right: ${theme.spacing.insetM};
vertical-align: bottom;
overflow: visible;
transform: translateY(-0.1em);

& .${svgPrefix}fi-toggle-icon-knob {
transform: translateX(0%);
}
.${svgPrefix}fi-toggle-icon-circle {
fill: ${theme.colors.whiteBase};
}
& .${svgPrefix}fi-toggle-icon-slide {
transform: translateY(1px);

& > .fi-toggle_input {
${element({ theme })}
${font({ theme })('bodyText')}
position: absolute;
width: ${iconWidth};
height: ${iconHeight};
opacity: 0;
z-index: -9999;
background-color: ${theme.colors.whiteBase};
}
&.fi-toggle_icon--disabled {

& .fi-toggle_icon {
width: ${iconWidth};
height: ${iconHeight};
vertical-align: bottom;
overflow: visible;
.${svgPrefix}fi-toggle-icon-circle {
fill: ${theme.colors.depthLight3};
fill: ${theme.colors.whiteBase};
}
& .${svgPrefix}fi-toggle-icon-slide {
fill: ${theme.colors.depthLight2};
}
}
&.fi-toggle_icon--checked {
.${svgPrefix}fi-toggle-icon-knob {
transform: translateX(50%);
}
.${svgPrefix}fi-toggle-icon-slide {
fill: ${theme.colors.successSecondary};
}
.${svgPrefix}fi-toggle-icon-circle {
fill: ${theme.colors.successBase};
transform: translateX(0%);
}
&.fi-toggle_icon--disabled {
.${svgPrefix}fi-toggle-icon-circle {
fill: ${theme.colors.successSecondary};
.${svgPrefix}fi-toggle-icon-circle {
fill: ${theme.colors.depthLight3};
}
& .${svgPrefix}fi-toggle-icon-slide {
fill: ${theme.colors.depthLight2};
}
}
&.fi-toggle_icon--checked {
.${svgPrefix}fi-toggle-icon-knob {
transform: translateX(47%);
}
.${svgPrefix}fi-toggle-icon-slide {
fill: ${theme.colors.successSecondary};
}
.${svgPrefix}fi-toggle-icon-circle {
fill: ${theme.colors.successBase};
}
&.fi-toggle_icon--disabled {
.${svgPrefix}fi-toggle-icon-circle {
fill: ${theme.colors.successSecondary};
}
}
}
}
}
}
`,
);
2 changes: 1 addition & 1 deletion src/core/Form/Toggle/Toggle.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const [checked, setChecked] = useState(false);
}
}}
>
Controlled checked state.
Controlled checked state
</Toggle>
</>;
```
18 changes: 11 additions & 7 deletions src/core/Form/Toggle/Toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import {
} from '../../../components/Form/Toggle';
import { ComponentIcon } from '../../StaticIcon/StaticIcon';
import { Text } from '../../Text/Text';
import { HtmlSpan } from '../../../reset';

export interface ToggleProps extends CompToggleProps, TokensProp {}
export interface ToggleInputProps extends CompToggleInputProps, TokensProp {}

const iconBaseClassName = 'fi-toggle_icon';
const iconContainerClassName = 'fi-toggle_icon-container';
const iconDisabledClassName = `${iconBaseClassName}--disabled`;
const iconCheckedClassName = `${iconBaseClassName}--checked`;

Expand Down Expand Up @@ -72,13 +74,15 @@ class ToggleWithIcon extends Component<ToggleProps> {
{...passProps}
onClick={this.handleToggle}
>
<ComponentIcon
icon="toggle"
className={classnames(iconBaseClassName, {
[iconDisabledClassName]: !!disabled,
[iconCheckedClassName]: !!toggleStatus,
})}
/>
<HtmlSpan className={iconContainerClassName}>
<ComponentIcon
icon="toggle"
className={classnames(iconBaseClassName, {
[iconDisabledClassName]: !!disabled,
[iconCheckedClassName]: !!toggleStatus,
})}
/>
</HtmlSpan>
<Text color={!!disabled ? 'depthBase' : 'blackBase'}>{children}</Text>
</StyledToggle>
);
Expand Down
Loading