Skip to content

Commit

Permalink
fix(fields): prefix styled custom props with $ (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele authored Dec 14, 2022
1 parent 644cc2b commit 05d03ba
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 32 deletions.
6 changes: 3 additions & 3 deletions src/components/Dropdown/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ export function Item({ Icon, ...originalProps }: DropdownItemProps) {
const icon = useMemo(() => (Icon ? <Icon size={1.25} /> : undefined), [Icon])
const hasIcon = useMemo(() => Boolean(Icon), [Icon])

return <StyledDropdownItem hasIcon={hasIcon} icon={icon} {...originalProps} />
return <StyledDropdownItem $hasIcon={hasIcon} icon={icon} {...originalProps} />
}

// TODO We need to split that into multiple styled components as done in `<Button />`.
const StyledDropdownItem = styled(RsuiteDropdown.Item)<{
hasIcon: boolean
$hasIcon: boolean
}>`
align-items: center;
display: flex;
font-size: 13px;
line-height: 1;
padding: 0.75rem;
padding: ${p => (p.hasIcon ? '9px' : '12.5px')} 12px;
padding: ${p => (p.$hasIcon ? '9px' : '12.5px')} 12px;
&:not(:last-child) {
border-bottom: 1px solid var(--lightGray);
Expand Down
6 changes: 3 additions & 3 deletions src/components/Dropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ function RawDropdown({ Icon, ...originalProps }: DropdownProps) {
const icon = useMemo(() => (Icon ? <Icon size={1.25} /> : undefined), [Icon])
const hasIcon = useMemo(() => Boolean(Icon), [Icon])

return <StyledDropdown hasIcon={hasIcon} icon={icon} {...originalProps} />
return <StyledDropdown $hasIcon={hasIcon} icon={icon} {...originalProps} />
}

// TODO We need to split into multiple styled components as done in `<Button />`.
const StyledDropdown = styled(RsuiteDropdown)<{
hasIcon: boolean
$hasIcon: boolean
}>`
.rs-btn {
align-items: center;
Expand All @@ -30,7 +30,7 @@ const StyledDropdown = styled(RsuiteDropdown)<{
color: ${p => p.theme.color.gainsboro};
display: flex;
font-size: 13px;
padding: ${p => (p.hasIcon ? '5px' : '6px')} 12px;
padding: ${p => (p.$hasIcon ? '5px' : '6px')} 12px;
:hover {
background-color: ${p => p.theme.color.blueYonder['100']};
Expand Down
1 change: 1 addition & 0 deletions src/fields/DatePicker/CalendarPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const GlobalStyleToHideBodyDialog: any = createGlobalStyle`
const Box = styled.div`
height: 0;
position: relative;
top: 0;
user-select: none;
.rs-picker-toggle {
Expand Down
10 changes: 5 additions & 5 deletions src/fields/MultiCheckbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function MultiCheckbox({
<Fieldset key={key}>
<Legend isHidden={isLabelHidden}>{label}</Legend>

<ChecboxesBox isInline={isInline}>
<ChecboxesBox $isInline={isInline}>
{options.map((option, index) => (
<Checkbox
// eslint-disable-next-line react/no-array-index-key
Expand All @@ -69,22 +69,22 @@ export function MultiCheckbox({
}

const ChecboxesBox = styled.div<{
isInline: boolean
$isInline: boolean
}>`
color: ${p => p.theme.color.gunMetal};
display: flex;
flex-direction: ${p => (p.isInline ? 'row' : 'column')};
flex-direction: ${p => (p.$isInline ? 'row' : 'column')};
${p =>
!p.isInline &&
!p.$isInline &&
css`
> .rs-checkbox:not(:first-child) {
margin-top: 0.5rem;
}
`}
${p =>
p.isInline &&
p.$isInline &&
css`
> .rs-checkbox:not(:first-child) {
margin-left: 0.75rem;
Expand Down
10 changes: 5 additions & 5 deletions src/fields/MultiRadio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function MultiRadio({
<Fieldset key={key}>
<Legend isHidden={isLabelHidden}>{label}</Legend>

<ChecboxesBox isInline={isInline}>
<ChecboxesBox $isInline={isInline}>
{options.map((option, index) => (
<Radio
// eslint-disable-next-line react/no-array-index-key
Expand All @@ -73,11 +73,11 @@ export function MultiRadio({
}

const ChecboxesBox = styled.div<{
isInline: boolean
$isInline: boolean
}>`
color: ${p => p.theme.color.gunMetal};
display: flex;
flex-direction: ${p => (p.isInline ? 'row' : 'column')};
flex-direction: ${p => (p.$isInline ? 'row' : 'column')};
font-weight: 500;
> .rs-radio {
Expand All @@ -93,15 +93,15 @@ const ChecboxesBox = styled.div<{
}
${p =>
!p.isInline &&
!p.$isInline &&
css`
> .rs-radio:not(:first-child) {
margin-top: 6px;
}
`}
${p =>
p.isInline &&
p.$isInline &&
css`
> .rs-radio:not(:first-child) {
margin-left: 0.75rem;
Expand Down
12 changes: 6 additions & 6 deletions src/fields/MultiSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ export function MultiSelect({

<StyledTagPicker
key={key}
$fixedWidth={fixedWidth}
$isLight={isLight}
data={options}
fixedWidth={fixedWidth}
id={originalProps.name}
isLight={isLight}
onChange={handleChange}
searchable={searchable}
{...originalProps}
Expand All @@ -72,15 +72,15 @@ export function MultiSelect({
// TODO A width seems to be mandatory in rsuite which is a very dirty behavior.
// We should hack that.
const StyledTagPicker = styled(TagPicker)<{
fixedWidth: number
isLight: boolean
$fixedWidth: number
$isLight: boolean
}>`
border: 0;
cursor: pointer;
width: ${p => p.fixedWidth}rem;
width: ${p => p.$fixedWidth}rem;
> .rs-picker-toggle {
background-color: ${p => (p.isLight ? p.theme.color.white : p.theme.color.gainsboro)} !important;
background-color: ${p => (p.$isLight ? p.theme.color.white : p.theme.color.gainsboro)} !important;
cursor: inherit;
}
`
6 changes: 3 additions & 3 deletions src/fields/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ export function Select({

<StyledSelectPicker
key={key}
$isLight={isLight}
data={options}
id={originalProps.name}
isLight={isLight}
// The `unknown` type from Rsuite library is wrong. It should be inferred from `data` prop type.
// `onChange: ((value: unknown, event: React.SyntheticEvent<Element, Event>) => void) | undefined`
onChange={handleChange as any}
Expand All @@ -68,10 +68,10 @@ export function Select({
}

const StyledSelectPicker = styled(SelectPicker)<{
isLight: boolean
$isLight: boolean
}>`
> .rs-picker-toggle {
background-color: ${p => (p.isLight ? p.theme.color.white : p.theme.color.gainsboro)} !important;
background-color: ${p => (p.$isLight ? p.theme.color.white : p.theme.color.gainsboro)} !important;
border: 0;
}
`
14 changes: 10 additions & 4 deletions src/fields/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ export type TextInputProps = Omit<InputProps, 'as' | 'defaultValue' | 'id' | 'on
name: string
onChange?: (nextValue: string | undefined) => Promisable<void>
}
export function TextInput({ isLabelHidden = false, label, onChange, ...originalProps }: TextInputProps) {
export function TextInput({
isLabelHidden = false,
isLight = false,
label,
onChange,
...originalProps
}: TextInputProps) {
const key = useMemo(
() => `${originalProps.name}-${JSON.stringify(originalProps.defaultValue)}`,
[originalProps.defaultValue, originalProps.name]
Expand All @@ -41,15 +47,15 @@ export function TextInput({ isLabelHidden = false, label, onChange, ...originalP
{label}
</Label>

<StyledInput key={key} id={originalProps.name} onChange={handleChange} {...originalProps} />
<StyledInput key={key} $isLight={isLight} id={originalProps.name} onChange={handleChange} {...originalProps} />
</Field>
)
}

const StyledInput = styled(Input)<{
isLight: boolean
$isLight: boolean
}>`
background-color: ${p => (p.isLight ? p.theme.color.white : p.theme.color.gainsboro)};
background-color: ${p => (p.$isLight ? p.theme.color.white : p.theme.color.gainsboro)};
border: 0;
font-size: 13px;
width: 100%;
Expand Down
6 changes: 3 additions & 3 deletions src/fields/Textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ export function Textarea({
<StyledInput
key={key}
ref={inputRef}
$isLight={isLight}
as="textarea"
id={originalProps.name}
isLight={isLight}
onChange={handleChange}
rows={rows}
{...originalProps}
Expand All @@ -66,9 +66,9 @@ export function Textarea({
}

const StyledInput = styled(Input)<{
isLight: boolean
$isLight: boolean
}>`
background-color: ${p => (p.isLight ? p.theme.color.white : p.theme.color.gainsboro)};
background-color: ${p => (p.$isLight ? p.theme.color.white : p.theme.color.gainsboro)};
border: 0;
font-size: 13px;
padding: 7px 11px;
Expand Down

0 comments on commit 05d03ba

Please sign in to comment.