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(icons): use rem on icons #4602

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
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 @@ -400,10 +400,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 @@ -638,10 +638,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 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 @@

const sizeStyles = ({
size,
theme,
}: {
size: keyof typeof SIZES | number | string

Check warning on line 31 in packages/icons/src/components/Icon/Icon.tsx

View workflow job for this annotation

GitHub Actions / lint

"small" | "large" | "xlarge" | "xxlarge" is overridden by string in this union type
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 Expand Up @@ -61,7 +64,7 @@
shouldForwardProp: prop =>
!['size', 'sentiment', 'prominence', 'disabled'].includes(prop),
})<{
sentiment: Color | string

Check warning on line 67 in packages/icons/src/components/Icon/Icon.tsx

View workflow job for this annotation

GitHub Actions / lint

"success" | "danger" | "info" | "neutral" | "primary" | "secondary" | "warning" is overridden by string in this union type
size: number | string
prominence: ProminenceProps
disabled?: boolean
Expand Down Expand Up @@ -106,7 +109,7 @@
/**
* **! IMPORTANT:** `string` and `number` are deprecated. Use `small`, `large`, `xlarge`, `xxlarge` only.
*/
size?: number | string | 'small' | 'large'

Check warning on line 112 in packages/icons/src/components/Icon/Icon.tsx

View workflow job for this annotation

GitHub Actions / lint

"small" is overridden by string in this union type

Check warning on line 112 in packages/icons/src/components/Icon/Icon.tsx

View workflow job for this annotation

GitHub Actions / lint

"large" is overridden by string in this union type
prominence?: ProminenceProps
/**
* @deprecated use `sentiment` property instead
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 @@ -1095,9 +1095,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 @@ -2270,9 +2270,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 @@ -3459,9 +3459,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 @@ -4516,9 +4516,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 @@ -5979,9 +5979,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 @@ -7442,9 +7442,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 @@ -8919,9 +8919,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 @@ -10378,9 +10378,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
Loading