Skip to content

Commit 815a3b2

Browse files
authored
feat: new icons and fixes (#30)
* refactor: move out styled component definitions https://styled-components.com/docs/faqs#why-should-i-avoid-declaring-styled-components-in-the-render-method * fix: render label as a component * fix: update checkbox label type * fix: allow margins to work correctly * feat: add fluid prop to button * feat: update ledger icon * chore: remove fluid prop from button * feat: add poly-pink icon
1 parent c14765e commit 815a3b2

3 files changed

Lines changed: 41 additions & 19 deletions

File tree

src/components/Checkbox/Checkbox.tsx

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FC } from 'react';
1+
import { FC, Fragment } from 'react';
22
import styled from 'styled-components';
33
import { Flex } from '../Flex';
44
import { getMargin, visuallyHidden } from '../../theme/utils';
@@ -14,7 +14,7 @@ export type CheckboxProps = {
1414
defaultChecked?: boolean;
1515
checked?: boolean;
1616
name?: string;
17-
label?: React.ComponentType | string;
17+
label?: React.ComponentType | JSX.Element | string;
1818
indeterminate?: boolean;
1919
};
2020

@@ -97,6 +97,22 @@ const CheckboxInput = styled.div(({ theme }) => ({
9797
},
9898
}));
9999

100+
const LabelComponent = styled.label<{ variant: string; margin?: string }>(
101+
({ theme, variant, margin }) => ({
102+
...(theme.CHECKBOX[variant] || {}),
103+
...(margin
104+
? {
105+
display: 'inline-block',
106+
margin: getMargin({ theme, margin }),
107+
}
108+
: {}),
109+
}),
110+
);
111+
112+
const Label = styled(Flex)<any>(({ theme }) => ({
113+
...(theme.CHECKBOX['labelMargin'] || {}),
114+
}));
115+
100116
export const Checkbox: FC<CheckboxProps> = ({
101117
variant,
102118
margin,
@@ -108,15 +124,6 @@ export const Checkbox: FC<CheckboxProps> = ({
108124
indeterminate,
109125
...props
110126
}) => {
111-
const Component = styled.label(({ theme }) => ({
112-
...(theme.CHECKBOX[variant] || {}),
113-
...(margin && { margin: getMargin({ theme, margin }) }),
114-
}));
115-
116-
const Label = styled(Flex)<any>(({ theme }) => ({
117-
...(theme.CHECKBOX['labelMargin'] || {}),
118-
}));
119-
120127
const checkedProps =
121128
typeof checked !== 'undefined' ? { checked } : { defaultChecked };
122129

@@ -127,7 +134,7 @@ export const Checkbox: FC<CheckboxProps> = ({
127134
};
128135

129136
return (
130-
<Component>
137+
<LabelComponent variant={variant} margin={margin}>
131138
<Flex variant="raw">
132139
<Input
133140
{...props}
@@ -153,12 +160,16 @@ export const Checkbox: FC<CheckboxProps> = ({
153160
className="checkIcon"
154161
/>
155162
</CheckboxInput>
156-
{label && (
157-
<Label variant="raw">
158-
<label htmlFor={name}>{label}</label>
159-
</Label>
160-
)}
163+
<Fragment key={`${name}Label`}>
164+
{typeof label === 'string' ? (
165+
<Label variant="raw">
166+
<label htmlFor={name}>{label}</label>
167+
</Label>
168+
) : (
169+
label
170+
)}
171+
</Fragment>
161172
</Flex>
162-
</Component>
173+
</LabelComponent>
163174
);
164175
};

src/theme/icons/svg/ledger.svg

Lines changed: 1 addition & 1 deletion
Loading

src/theme/icons/svg/poly-pink.svg

Lines changed: 11 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)