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

Add --checked-color to checkbox #363

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
49 changes: 47 additions & 2 deletions src/components/inputs/Checkbox/Checkbox.story.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React from 'react';
import { Story } from '@storybook/react';
import { StoryFn } from '@storybook/react';

import { Checkbox, Props } from './Checkbox';

import { Layout } from '../../../storybook';

import styled from 'styled-components';

export default {
title: 'components/Checkbox',
component: Checkbox,
Expand Down Expand Up @@ -32,16 +34,59 @@ export default {
},
};

const Template: Story<Props> = (args) => {
const Template: StoryFn<Props> = (args) => {
return (
<Layout.StoryVertical>
<Checkbox {...args} />
</Layout.StoryVertical>
);
};

export const Controls = Template.bind({});
Controls.storyName = 'Checkbox';
Controls.args = {
label: 'Checkbox label',
value: 'checkbox1',
};

export const StickerSheet = () => (
<Layout.StoryVertical>
<Checkbox label="default" value="default" />
<Checkbox label="default disabled" value="default" disabled />
<Checkbox label="default checked" value="default" checked />
<Checkbox label="default checked disabled" checked disabled />
<Checkbox
label="default checked disabled indeterminate"
checked
disabled
indeterminate
/>
<Checkbox
style={{ '--checked-color': 'black' } as React.CSSProperties}
label="--checked-color:black"
/>
<Checkbox
style={{ '--checked-color': 'black' } as React.CSSProperties}
label="--checked-color:black disabled"
disabled
/>
<Checkbox
style={{ '--checked-color': 'black' } as React.CSSProperties}
label="--checked-color:black checked"
checked
/>
<Checkbox
style={{ '--checked-color': 'black' } as React.CSSProperties}
label="--checked-color:black disabled"
checked
disabled
/>
<Checkbox
style={{ '--checked-color': 'black' } as React.CSSProperties}
label="--checked-color:black disabled indeterminate"
checked
indeterminate
disabled
/>
</Layout.StoryVertical>
);
12 changes: 8 additions & 4 deletions src/components/inputs/Input/Input.style.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import styled, { css, StyledComponent } from 'styled-components';
import { rgba, darken } from 'polished';
import { darken, rem } from 'polished';
import { grayscale, slate } from '../../../color';

import {
Expand Down Expand Up @@ -59,11 +59,15 @@ export const HiddenMark: StyledComponent<
function fauxMarkChecked({ disabled }) {
return css`
&:checked ~ ${Faux} {
border: 1px solid ${rgba(blue(500), disabled ? 0 : 1)};
border-style: solid;
border-width: 1px;
${!disabled &&
`border-color: var(--checked-color, ${blue(500)})`};

&:after {
border-radius: ${rem(2)};
opacity: ${disabled ? 0.5 : 1};
transform: scale(1.02);
transform: scale(1.1);
}
}
`;
Expand Down Expand Up @@ -148,7 +152,7 @@ export function FauxType({ type, size }) {
&:after {
width: 100%;
height: 100%;
border: 1px solid ${blue(500)};
border: 1px solid var(--checked-color, ${blue(500)});
background-image: ${checkmark};
}
`;
Expand Down
2 changes: 1 addition & 1 deletion src/components/inputs/Shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export const FauxMark = (type, mirror) =>
&:after {
content: '';
display: block;
background: ${blue(500)};
background: var(--checked-color, ${blue(500)});
opacity: 0;
transition: 200ms ease-in-out;
transform: scale(0);
Expand Down
Loading