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

feat: add large size to checkbox and radio inputs #57

Merged
merged 1 commit into from
Oct 6, 2021
Merged
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
8 changes: 7 additions & 1 deletion packages/checkbox/src/Checkbox.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ThemeProvider as EmotionThemeProvider } from '@emotion/react';
import { Story, Meta } from '@storybook/react';
import { DARK_COLORS, CLASSIC_COLORS } from '@tablecheck/tablekit-theme';
import { DARK_COLORS, CLASSIC_COLORS, Size } from '@tablecheck/tablekit-theme';
import { useState } from 'react';
import { useDarkMode } from 'storybook-dark-mode';

Expand Down Expand Up @@ -57,6 +57,12 @@ Default.args = {
children: 'Default'
};

export const LargeSize = Template.bind({});
LargeSize.args = {
size: Size.Large,
children: 'Large Size'
};

export const Required = Template.bind({});
Required.args = {
isRequired: true,
Expand Down
12 changes: 8 additions & 4 deletions packages/checkbox/src/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
CheckboxInput,
InputDisplay,
CheckboxLabel,
RequiredIndicator
RequiredIndicator,
CheckboxText
} from './styled';
import { CheckboxProps } from './types';

Expand Down Expand Up @@ -39,6 +40,7 @@ export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
onChange,
value,
children,
size,
...inputProps
} = props;

Expand Down Expand Up @@ -74,7 +76,7 @@ export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
checked={isChecked}
type="checkbox"
/>
<InputDisplay isInvalid={isInvalid}>
<InputDisplay isInvalid={isInvalid} data-size={size}>
<svg
width="12px"
height="12px"
Expand All @@ -85,9 +87,11 @@ export const Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(
<polyline className="checkbox-checkmark" points="1 3 4 6 9 1" />
</svg>
</InputDisplay>
<p>{children}</p>
<CheckboxText data-size={size}>{children}</CheckboxText>
{isRequired ? (
<RequiredIndicator role="presentation">*</RequiredIndicator>
<RequiredIndicator role="presentation" data-size={size}>
*
</RequiredIndicator>
) : null}
</CheckboxLabel>
);
Expand Down
16 changes: 15 additions & 1 deletion packages/checkbox/src/styled.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { css } from '@emotion/react';
import styled from '@emotion/styled';
import { Spacing, FieldHeight } from '@tablecheck/tablekit-theme';
import { Spacing, FieldHeight, Size } from '@tablecheck/tablekit-theme';
import { Typography } from '@tablecheck/tablekit-typography';
import { getThemeValue } from '@tablecheck/tablekit-utils';
import type { ThemeOnlyProps } from '@tablecheck/tablekit-utils';
Expand All @@ -11,6 +11,7 @@ import {
IS_CLICKED_SELECTOR
} from './constants';
import { checkboxClassicTheme, checkboxThemeNamespace } from './themes';
import { CheckboxProps } from './types';

export const Text = styled.span`
display: inline-flex;
Expand All @@ -27,8 +28,17 @@ export const RequiredIndicator = styled.span`
font-weight: bold;
`;

export const CheckboxText = styled.p<{
'data-size'?: CheckboxProps['size'];
}>`
&[data-size='${Size.Large}'] {
${Typography.Body1};
}
`;

export const InputDisplay = styled.span<{
isInvalid?: boolean;
'data-size'?: CheckboxProps['size'];
}>`
background: ${getThemeValue(
`${checkboxThemeNamespace}.backgroundColorBox`,
Expand All @@ -49,6 +59,10 @@ export const InputDisplay = styled.span<{
vertical-align: text-bottom;
height: 20px;
width: 20px;
&[data-size='${Size.Large}'] {
width: 24px;
height: 24px;
}

svg {
position: absolute;
Expand Down
3 changes: 3 additions & 0 deletions packages/checkbox/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Size } from '@tablecheck/tablekit-theme';
import { ReactNode, HTMLAttributes } from 'react';

export type Value = string | number | readonly string[] | undefined;
Expand Down Expand Up @@ -27,4 +28,6 @@ export type CheckboxProps = HTMLAttributes<HTMLInputElement> &

/** Field value */
value: Value;

size?: Size.Regular | Size.Large;
}>;
7 changes: 7 additions & 0 deletions packages/radio/src/Radio.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Story, Meta } from '@storybook/react';
import { Size } from '@tablecheck/tablekit-theme';
import { useState } from 'react';

import { RadioProps } from './types';
Expand Down Expand Up @@ -35,6 +36,12 @@ const Template: Story<RadioProps> = ({ ...args }) => (
<Radio {...args}>{args.children}</Radio>
);

export const LargeSize = Template.bind({});
LargeSize.args = {
size: Size.Large,
children: 'Large Size'
};

export const Required = Template.bind({});
Required.args = {
isRequired: true,
Expand Down
5 changes: 3 additions & 2 deletions packages/radio/src/Radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const Radio = forwardRef<HTMLInputElement, RadioProps>(
onChange,
value,
children,
size,
...inputProps
} = props;

Expand Down Expand Up @@ -74,8 +75,8 @@ export const Radio = forwardRef<HTMLInputElement, RadioProps>(
value={value}
ref={ref}
/>
<RadioInputDisplay />
<RadioText>{children}</RadioText>
<RadioInputDisplay data-size={size} />
<RadioText data-size={size}>{children}</RadioText>
</RadioLabel>
);
}
Expand Down
27 changes: 21 additions & 6 deletions packages/radio/src/styled.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import styled from '@emotion/styled';
import { Spacing, FieldHeight } from '@tablecheck/tablekit-theme';
import { Spacing, FieldHeight, Size } from '@tablecheck/tablekit-theme';
import { Typography } from '@tablecheck/tablekit-typography';
import { getThemeValue } from '@tablecheck/tablekit-utils';

import { radioClassicTheme, radioThemeNamespace } from './themes';
import { RadioProps } from './types';

export const IS_CLICKED_ATTR = 'isClicked';
const IS_CLICKED_SELECTOR = '[data-is-clicked="true"]';
Expand All @@ -13,12 +14,22 @@ const TRANSITION_SETTINGS = `${TRANSITION_SPEED} ease-in-out`;

export const RadioText = styled.span`
${Typography.Body2};
&[data-size='${Size.Large}'] {
${Typography.Body1};
}
`;

export const RadioInputDisplay = styled.span`
export const RadioInputDisplay = styled.span<{
'data-size'?: RadioProps['size'];
}>`
position: relative;
width: ${Spacing.L4};
height: ${Spacing.L4};

width: 16px;
height: 16px;
&[data-size='${Size.Large}'] {
width: 24px;
height: 24px;
}
background: ${getThemeValue(
`${radioThemeNamespace}.default.backgroundColor`,
radioClassicTheme.default.backgroundColor
Expand Down Expand Up @@ -57,13 +68,17 @@ export const RadioInputDisplay = styled.span`
position: absolute;
top: -1px; // Offset for border
left: -1px;
width: ${Spacing.L4};
height: ${Spacing.L4};
width: 16px;
height: 16px;
border-radius: 50%;
background: ${({ theme }) => theme.colors.primary2};
transform: scale(0);
transition: transform ${TRANSITION_SETTINGS};
}
&[data-size='${Size.Large}']::after {
width: 24px;
height: 24px;
}
`;

export const RadioInput = styled.input`
Expand Down
3 changes: 3 additions & 0 deletions packages/radio/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Size } from '@tablecheck/tablekit-theme';
import { ReactNode, HTMLAttributes } from 'react';

export type Value = string | number | readonly string[] | undefined;
Expand All @@ -22,4 +23,6 @@ export type RadioProps = HTMLAttributes<HTMLInputElement> & {

/** Field value */
value: Value;

size?: Size.Regular | Size.Large;
};