Skip to content

Commit

Permalink
feat(icons): use rem on icons (#4602)
Browse files Browse the repository at this point in the history
* feat(icons): use rem on icons

* fix: unit testing
  • Loading branch information
matthprost authored Jan 6, 2025
1 parent 9972cc5 commit 9fd969e
Show file tree
Hide file tree
Showing 17 changed files with 302 additions and 294 deletions.
5 changes: 5 additions & 0 deletions .changeset/stupid-teachers-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ultraviolet/icons": minor
---

Migrate icons sizes from px to remu using new theme `sizing` prop
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ exports[`DateField > should render correctly 1`] = `
.emotion-12 {
vertical-align: middle;
fill: #3f4250;
height: 20px;
width: 20px;
min-width: 20px;
min-height: 20px;
height: 1.25rem;
width: 1.25rem;
min-width: 1.25rem;
min-height: 1.25rem;
}
.emotion-12 .fillStroke {
Expand Down Expand Up @@ -399,10 +399,10 @@ exports[`DateField > should render correctly disabled 1`] = `
.emotion-12 {
vertical-align: middle;
fill: #b5b7bd;
height: 20px;
width: 20px;
min-width: 20px;
min-height: 20px;
height: 1.25rem;
width: 1.25rem;
min-width: 1.25rem;
min-height: 1.25rem;
}
.emotion-12 .fillStroke {
Expand Down Expand Up @@ -636,10 +636,10 @@ exports[`DateField > should trigger events 1`] = `
.emotion-12 {
vertical-align: middle;
fill: #3f4250;
height: 20px;
width: 20px;
min-width: 20px;
min-height: 20px;
height: 1.25rem;
width: 1.25rem;
min-width: 1.25rem;
min-height: 1.25rem;
}
.emotion-12 .fillStroke {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ exports[`SelectInputField > should display right value on grouped options 1`] =
.emotion-13 {
vertical-align: middle;
fill: #3f4250;
height: 16px;
width: 16px;
min-width: 16px;
min-height: 16px;
height: 1rem;
width: 1rem;
min-width: 1rem;
min-height: 1rem;
}
.emotion-13 .fillStroke {
Expand Down Expand Up @@ -1075,10 +1075,10 @@ exports[`SelectInputField > should render correctly 1`] = `
.emotion-13 {
vertical-align: middle;
fill: #3f4250;
height: 16px;
width: 16px;
min-width: 16px;
min-height: 16px;
height: 1rem;
width: 1rem;
min-width: 1rem;
min-height: 1rem;
}
.emotion-13 .fillStroke {
Expand Down Expand Up @@ -1343,10 +1343,10 @@ exports[`SelectInputField > should render correctly disabled 1`] = `
.emotion-13 {
vertical-align: middle;
fill: #b5b7bd;
height: 16px;
width: 16px;
min-width: 16px;
min-height: 16px;
height: 1rem;
width: 1rem;
min-width: 1rem;
min-height: 1rem;
}
.emotion-13 .fillStroke {
Expand Down Expand Up @@ -1611,10 +1611,10 @@ exports[`SelectInputField > should render correctly grouped 1`] = `
.emotion-13 {
vertical-align: middle;
fill: #3f4250;
height: 16px;
width: 16px;
min-width: 16px;
min-height: 16px;
height: 1rem;
width: 1rem;
min-width: 1rem;
min-height: 1rem;
}
.emotion-13 .fillStroke {
Expand Down Expand Up @@ -1879,10 +1879,10 @@ exports[`SelectInputField > should render correctly multiselect 1`] = `
.emotion-13 {
vertical-align: middle;
fill: #3f4250;
height: 16px;
width: 16px;
min-width: 16px;
min-height: 16px;
height: 1rem;
width: 1rem;
min-width: 1rem;
min-height: 1rem;
}
.emotion-13 .fillStroke {
Expand Down Expand Up @@ -2145,10 +2145,10 @@ exports[`SelectInputField > should trigger events 1`] = `
.emotion-13 {
vertical-align: middle;
fill: #3f4250;
height: 16px;
width: 16px;
min-width: 16px;
min-height: 16px;
height: 1rem;
width: 1rem;
min-width: 1rem;
min-height: 1rem;
}
.emotion-13 .fillStroke {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,10 +459,10 @@ exports[`UnitInputField > should handles onChange and selection 1`] = `
.emotion-28 {
vertical-align: middle;
fill: #3f4250;
height: 16px;
width: 16px;
min-width: 16px;
min-height: 16px;
height: 1rem;
width: 1rem;
min-width: 1rem;
min-height: 1rem;
}
.emotion-28 .fillStroke {
Expand Down Expand Up @@ -1090,10 +1090,10 @@ exports[`UnitInputField > should render correctly 1`] = `
.emotion-26 {
vertical-align: middle;
fill: #3f4250;
height: 16px;
width: 16px;
min-width: 16px;
min-height: 16px;
height: 1rem;
width: 1rem;
min-width: 1rem;
min-height: 1rem;
}
.emotion-26 .fillStroke {
Expand Down
19 changes: 11 additions & 8 deletions packages/icons/src/components/Icon/Icon.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Theme } from '@emotion/react'
import { css } from '@emotion/react'
import styled from '@emotion/styled'
import type { consoleLightTheme as theme } from '@ultraviolet/themes'
Expand All @@ -6,10 +7,10 @@ import { forwardRef } from 'react'
import capitalize from '../../utils/capitalize'

const SIZES = {
small: 16,
large: 20,
xlarge: 32,
xxlarge: 56,
small: '200',
large: '250',
xlarge: '400',
xxlarge: '700',
} as const

type Color = Extract<
Expand All @@ -25,15 +26,17 @@ type Color = Extract<

const sizeStyles = ({
size,
theme,
}: {
size: keyof typeof SIZES | number | string
theme: Theme
}) => {
if (typeof size === 'string' && size in SIZES) {
return css`
height: ${SIZES[size as keyof typeof SIZES]}px;
width: ${SIZES[size as keyof typeof SIZES]}px;
min-width: ${SIZES[size as keyof typeof SIZES]}px;
min-height: ${SIZES[size as keyof typeof SIZES]}px;
height: ${theme.sizing[SIZES[size as keyof typeof SIZES]]};
width: ${theme.sizing[SIZES[size as keyof typeof SIZES]]};
min-width: ${theme.sizing[SIZES[size as keyof typeof SIZES]]};
min-height: ${theme.sizing[SIZES[size as keyof typeof SIZES]]};
`
}

Expand Down
16 changes: 8 additions & 8 deletions packages/icons/src/components/Logo/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import styled from '@emotion/styled'
import type { ReactNode } from 'react'

const SIZES = {
small: 16,
medium: 20,
large: 32,
xlarge: 56,
}
small: '200',
medium: '250',
large: '400',
xlarge: '700',
} as const

const StyledIcon = styled('svg', {
shouldForwardProp: prop => !['size'].includes(prop),
})<{ size: keyof typeof SIZES }>`
& {
width: ${({ size }) => `${SIZES[size]}px`};
min-width: ${({ size }) => `${SIZES[size]}px`}; // This is to avoid the icon to shrink when the text is too long
height: ${({ size }) => `${SIZES[size]}px`};
width: ${({ size, theme }) => `${theme.sizing[SIZES[size]]}`};
min-width: ${({ size, theme }) => `${theme.sizing[SIZES[size]]}`}; // This is to avoid the icon to shrink when the text is too long
height: ${({ size, theme }) => `${theme.sizing[SIZES[size]]}`};
}
`

Expand Down
16 changes: 8 additions & 8 deletions packages/icons/src/components/ProductIcon/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import type { ReactNode } from 'react'
type Variants = 'primary' | 'danger' | 'warning' | 'original'

export const SIZES = {
xsmall: 24,
small: 32,
medium: 40,
large: 48,
xlarge: 64,
xsmall: '300',
small: '400',
medium: '500',
large: '600',
xlarge: '800',
} as const

const StyledIcon = styled('svg', {
shouldForwardProp: prop => !['variant', 'disabled'].includes(prop),
})<{ variant: Variants; disabled?: boolean; size: keyof typeof SIZES }>`
& {
width: ${({ size }) => `${SIZES[size]}px`};
min-width: ${({ size }) => `${SIZES[size]}px`}; // This is to avoid the icon to shrink when the text is too long
height: ${({ size }) => `${SIZES[size]}px`};
width: ${({ size, theme }) => `${theme.sizing[SIZES[size]]}`};
min-width: ${({ size, theme }) => `${theme.sizing[SIZES[size]]}`}; // This is to avoid the icon to shrink when the text is too long
height: ${({ size, theme }) => `${theme.sizing[SIZES[size]]}`};
}
path[fill].fill,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,9 @@ exports[`FAQ > should work with productIconName 1`] = `
}
.emotion-5 {
width: 64px;
min-width: 64px;
height: 64px;
width: 4rem;
min-width: 4rem;
height: 4rem;
}
.emotion-5 path[fill].fill,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1091,9 +1091,9 @@ exports[`AvatarV2 > renders correctly with shape circle > renders correctly with
}
.emotion-4 {
width: 32px;
min-width: 32px;
height: 32px;
width: 2rem;
min-width: 2rem;
height: 2rem;
}
.emotion-4 path[fill].fill,
Expand Down Expand Up @@ -2262,9 +2262,9 @@ exports[`AvatarV2 > renders correctly with shape circle > renders correctly with
}
.emotion-4 {
width: 32px;
min-width: 32px;
height: 32px;
width: 2rem;
min-width: 2rem;
height: 2rem;
}
.emotion-4 path[fill].fill,
Expand Down Expand Up @@ -3447,9 +3447,9 @@ exports[`AvatarV2 > renders correctly with shape circle > renders correctly with
}
.emotion-4 {
width: 32px;
min-width: 32px;
height: 32px;
width: 2rem;
min-width: 2rem;
height: 2rem;
}
.emotion-4 path[fill].fill,
Expand Down Expand Up @@ -4504,9 +4504,9 @@ exports[`AvatarV2 > renders correctly with shape circle > renders correctly with
}
.emotion-4 {
width: 32px;
min-width: 32px;
height: 32px;
width: 2rem;
min-width: 2rem;
height: 2rem;
}
.emotion-4 path[fill].fill,
Expand Down Expand Up @@ -5963,9 +5963,9 @@ exports[`AvatarV2 > renders correctly with shape square > renders correctly with
}
.emotion-4 {
width: 32px;
min-width: 32px;
height: 32px;
width: 2rem;
min-width: 2rem;
height: 2rem;
}
.emotion-4 path[fill].fill,
Expand Down Expand Up @@ -7422,9 +7422,9 @@ exports[`AvatarV2 > renders correctly with shape square > renders correctly with
}
.emotion-4 {
width: 32px;
min-width: 32px;
height: 32px;
width: 2rem;
min-width: 2rem;
height: 2rem;
}
.emotion-4 path[fill].fill,
Expand Down Expand Up @@ -8895,9 +8895,9 @@ exports[`AvatarV2 > renders correctly with shape square > renders correctly with
}
.emotion-4 {
width: 32px;
min-width: 32px;
height: 32px;
width: 2rem;
min-width: 2rem;
height: 2rem;
}
.emotion-4 path[fill].fill,
Expand Down Expand Up @@ -10354,9 +10354,9 @@ exports[`AvatarV2 > renders correctly with shape square > renders correctly with
}
.emotion-4 {
width: 32px;
min-width: 32px;
height: 32px;
width: 2rem;
min-width: 2rem;
height: 2rem;
}
.emotion-4 path[fill].fill,
Expand Down
Loading

0 comments on commit 9fd969e

Please sign in to comment.