diff --git a/.changeset/empty-boats-care.md b/.changeset/empty-boats-care.md new file mode 100644 index 00000000000..5c3980891db --- /dev/null +++ b/.changeset/empty-boats-care.md @@ -0,0 +1,9 @@ +--- +"@razorpay/blade": minor +--- + +fix(Blade): add `size` prop to Text component and update tokens + +This PR updates the typography tokens scale for mobile devices to create better visual hierarchy which we received as feedback from other teams as well. + +It also adds a new `size` prop to `Text` component for `variant='body'` diff --git a/packages/blade/src/components/Button/BaseButton/BaseButton.tsx b/packages/blade/src/components/Button/BaseButton/BaseButton.tsx index a8d1175a348..319285178bc 100644 --- a/packages/blade/src/components/Button/BaseButton/BaseButton.tsx +++ b/packages/blade/src/components/Button/BaseButton/BaseButton.tsx @@ -1,6 +1,5 @@ import { useEffect } from 'react'; import styled from 'styled-components'; - import type { ReactElement } from 'react'; import StyledBaseButton from './StyledBaseButton'; import type { ButtonTypography, ButtonMinHeight } from './buttonTokens'; @@ -17,7 +16,6 @@ import type { Theme } from '~components/BladeProvider'; import type { SpinnerSize } from '~components/Spinner/spinnerTokens'; import type { BaseTextProps } from '~components/Typography/BaseText'; import type { IconComponent, IconProps, IconSize } from '~components/Icons'; -import type { TypographyPlatforms } from '~tokens/global/typography'; import type { DurationString, EasingString } from '~tokens/global/motion'; import type { BorderRadiusValues, BorderWidthValues, SpacingValues } from '~tokens/theme/theme'; import { makeAccessible, usePrevious, makeSize, makeSpace, makeBorderSize, getIn } from '~utils'; @@ -138,7 +136,7 @@ const getProps = ({ hasIcon, iconPosition, }: { - buttonTypographyTokens: ButtonTypography[TypographyPlatforms]; + buttonTypographyTokens: ButtonTypography; children?: string; isDisabled: boolean; hasIcon: boolean; @@ -271,8 +269,7 @@ const BaseButton = ({ accessibilityLabel, }: BaseButtonProps): ReactElement => { const disabled = isLoading || isDisabled; - const { theme, platform } = useTheme(); - const buttonTypographyTokens = buttonTypography[platform]; + const { theme } = useTheme(); if (!Icon && !children?.trim()) { throw new Error( `[Blade: BaseButton]: At least one of icon or text is required to render a button.`, @@ -316,7 +313,7 @@ const BaseButton = ({ motionDuration, motionEasing, } = getProps({ - buttonTypographyTokens, + buttonTypographyTokens: buttonTypography, children, isDisabled: disabled, size, diff --git a/packages/blade/src/components/Button/BaseButton/__tests__/__snapshots__/BaseButton.native.test.tsx.snap b/packages/blade/src/components/Button/BaseButton/__tests__/__snapshots__/BaseButton.native.test.tsx.snap index 979d8516cad..7be4a2989b2 100644 --- a/packages/blade/src/components/Button/BaseButton/__tests__/__snapshots__/BaseButton.native.test.tsx.snap +++ b/packages/blade/src/components/Button/BaseButton/__tests__/__snapshots__/BaseButton.native.test.tsx.snap @@ -89,7 +89,7 @@ exports[` should render button with default properties 1`] = ` fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -98,7 +98,7 @@ exports[` should render button with default properties 1`] = ` "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -206,7 +206,7 @@ exports[` should render button with full width 1`] = ` fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -215,7 +215,7 @@ exports[` should render button with full width 1`] = ` "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -374,7 +374,7 @@ exports[` should render button with icon with default iconPosition fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -383,7 +383,7 @@ exports[` should render button with icon with default iconPosition "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -542,7 +542,7 @@ exports[` should render button with icon with left iconPosition 1` fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -551,7 +551,7 @@ exports[` should render button with icon with left iconPosition 1` "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -659,7 +659,7 @@ exports[` should render button with icon with right iconPosition 1 fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -668,7 +668,7 @@ exports[` should render button with icon with right iconPosition 1 "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -965,7 +965,7 @@ exports[` should render disabled button 1`] = ` fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -974,7 +974,7 @@ exports[` should render disabled button 1`] = ` "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -1082,7 +1082,7 @@ exports[` should render disabled information intent high contrast fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -1091,7 +1091,7 @@ exports[` should render disabled information intent high contrast "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -1199,7 +1199,7 @@ exports[` should render disabled information intent low contrast b fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -1208,7 +1208,7 @@ exports[` should render disabled information intent low contrast b "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -1316,7 +1316,7 @@ exports[` should render disabled negative intent high contrast but fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -1325,7 +1325,7 @@ exports[` should render disabled negative intent high contrast but "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -1433,7 +1433,7 @@ exports[` should render disabled negative intent low contrast butt fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -1442,7 +1442,7 @@ exports[` should render disabled negative intent low contrast butt "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -1550,7 +1550,7 @@ exports[` should render disabled neutral intent high contrast butt fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -1559,7 +1559,7 @@ exports[` should render disabled neutral intent high contrast butt "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -1667,7 +1667,7 @@ exports[` should render disabled neutral intent low contrast butto fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -1676,7 +1676,7 @@ exports[` should render disabled neutral intent low contrast butto "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -1784,7 +1784,7 @@ exports[` should render disabled notice intent high contrast butto fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -1793,7 +1793,7 @@ exports[` should render disabled notice intent high contrast butto "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -1901,7 +1901,7 @@ exports[` should render disabled notice intent low contrast button fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -1910,7 +1910,7 @@ exports[` should render disabled notice intent low contrast button "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -2018,7 +2018,7 @@ exports[` should render disabled positive intent high contrast but fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -2027,7 +2027,7 @@ exports[` should render disabled positive intent high contrast but "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -2135,7 +2135,7 @@ exports[` should render disabled positive intent low contrast butt fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -2144,7 +2144,7 @@ exports[` should render disabled positive intent low contrast butt "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -2252,7 +2252,7 @@ exports[` should render disabled secondary variant button 1`] = ` fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -2261,7 +2261,7 @@ exports[` should render disabled secondary variant button 1`] = ` "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -2369,7 +2369,7 @@ exports[` should render disabled tertiary variant button 1`] = ` fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -2378,7 +2378,7 @@ exports[` should render disabled tertiary variant button 1`] = ` "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -2486,7 +2486,7 @@ exports[` should render information intent high contrast button 1` fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -2495,7 +2495,7 @@ exports[` should render information intent high contrast button 1` "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -2603,7 +2603,7 @@ exports[` should render information intent low contrast button 1`] fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -2612,7 +2612,7 @@ exports[` should render information intent low contrast button 1`] "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -2720,7 +2720,7 @@ exports[` should render large size button 1`] = ` fontSize="17px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="18px" style={ Array [ Object { @@ -2729,7 +2729,7 @@ exports[` should render large size button 1`] = ` "fontSize": 17, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 18, "textAlign": "center", "textDecorationLine": "none", }, @@ -2837,7 +2837,7 @@ exports[` should render medium size button 1`] = ` fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -2846,7 +2846,7 @@ exports[` should render medium size button 1`] = ` "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -2954,7 +2954,7 @@ exports[` should render negative intent high contrast button 1`] = fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -2963,7 +2963,7 @@ exports[` should render negative intent high contrast button 1`] = "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -3071,7 +3071,7 @@ exports[` should render negative intent low contrast button 1`] = fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -3080,7 +3080,7 @@ exports[` should render negative intent low contrast button 1`] = "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -3188,7 +3188,7 @@ exports[` should render neutral intent high contrast button 1`] = fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -3197,7 +3197,7 @@ exports[` should render neutral intent high contrast button 1`] = "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -3305,7 +3305,7 @@ exports[` should render neutral intent low contrast button 1`] = ` fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -3314,7 +3314,7 @@ exports[` should render neutral intent low contrast button 1`] = ` "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -3422,7 +3422,7 @@ exports[` should render notice intent high contrast button 1`] = ` fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -3431,7 +3431,7 @@ exports[` should render notice intent high contrast button 1`] = ` "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -3539,7 +3539,7 @@ exports[` should render notice intent low contrast button 1`] = ` fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -3548,7 +3548,7 @@ exports[` should render notice intent low contrast button 1`] = ` "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -3656,7 +3656,7 @@ exports[` should render positive intent high contrast button 1`] = fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -3665,7 +3665,7 @@ exports[` should render positive intent high contrast button 1`] = "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -3773,7 +3773,7 @@ exports[` should render positive intent low contrast button 1`] = fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -3782,7 +3782,7 @@ exports[` should render positive intent low contrast button 1`] = "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -3890,7 +3890,7 @@ exports[` should render secondary variant button 1`] = ` fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -3899,7 +3899,7 @@ exports[` should render secondary variant button 1`] = ` "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, @@ -4124,7 +4124,7 @@ exports[` should render tertiary variant button 1`] = ` fontSize="15px" fontStyle="normal" fontWeight={700} - lineHeight="16px" + lineHeight="24px" style={ Array [ Object { @@ -4133,7 +4133,7 @@ exports[` should render tertiary variant button 1`] = ` "fontSize": 15, "fontStyle": "normal", "fontWeight": "700", - "lineHeight": 16, + "lineHeight": 24, "textAlign": "center", "textDecorationLine": "none", }, diff --git a/packages/blade/src/components/Button/BaseButton/__tests__/__snapshots__/BaseButton.web.test.tsx.snap b/packages/blade/src/components/Button/BaseButton/__tests__/__snapshots__/BaseButton.web.test.tsx.snap index f29f7842314..f0e6deebcd6 100644 --- a/packages/blade/src/components/Button/BaseButton/__tests__/__snapshots__/BaseButton.web.test.tsx.snap +++ b/packages/blade/src/components/Button/BaseButton/__tests__/__snapshots__/BaseButton.web.test.tsx.snap @@ -4266,7 +4266,7 @@ exports[` should render small size button 1`] = ` font-style: normal; -webkit-text-decoration-line: none; text-decoration-line: none; - line-height: 1.25rem; + line-height: 1rem; text-align: center; } @@ -4524,7 +4524,7 @@ exports[` should render xsmall size button 1`] = ` font-style: normal; -webkit-text-decoration-line: none; text-decoration-line: none; - line-height: 1.25rem; + line-height: 1rem; text-align: center; } diff --git a/packages/blade/src/components/Button/BaseButton/buttonTokens.ts b/packages/blade/src/components/Button/BaseButton/buttonTokens.ts index 6ccd436b090..adca8db08f6 100644 --- a/packages/blade/src/components/Button/BaseButton/buttonTokens.ts +++ b/packages/blade/src/components/Button/BaseButton/buttonTokens.ts @@ -1,58 +1,34 @@ import type { BaseButtonProps } from './BaseButton'; -import type { ThemeTokens } from '~tokens/theme/theme'; -import type { TypographyPlatforms } from '~tokens/global/typography'; +import type { Theme } from '~components/BladeProvider'; import type { IconProps } from '~components/Icons'; import type { SpinnerProps } from '~components/Spinner/Spinner'; export type ButtonMinHeight = 28 | 32 | 36 | 48; export type ButtonTypography = { - [Key in TypographyPlatforms]: { - fonts: { - size: Record< - NonNullable, - keyof ThemeTokens['typography'][Key]['fonts']['size'] - >; - }; - lineHeights: Record< - NonNullable, - keyof ThemeTokens['typography'][Key]['lineHeights'] - >; + fonts: { + size: Record, keyof Theme['typography']['fonts']['size']>; }; + lineHeights: Record< + NonNullable, + keyof Theme['typography']['lineHeights'] + >; }; const typography: ButtonTypography = { - onDesktop: { - fonts: { - size: { - xsmall: 75, - small: 75, - medium: 100, - large: 200, - }, - }, - lineHeights: { - xsmall: 'l', - small: 'l', - medium: 'l', - large: 's', + fonts: { + size: { + xsmall: 75, + small: 75, + medium: 100, + large: 200, }, }, - onMobile: { - fonts: { - size: { - xsmall: 50, - small: 50, - medium: 100, - large: 200, - }, - }, - lineHeights: { - xsmall: 's', - small: 's', - medium: 'm', - large: 'm', - }, + lineHeights: { + xsmall: 's', + small: 's', + medium: 'l', + large: 'm', }, }; @@ -65,7 +41,7 @@ const minHeight: Record, ButtonMinHeight> = const buttonPadding: Record< NonNullable, - Record<'top' | 'bottom' | 'left' | 'right', keyof ThemeTokens['spacing']> + Record<'top' | 'bottom' | 'left' | 'right', keyof Theme['spacing']> > = { xsmall: { top: 0, @@ -110,7 +86,7 @@ const buttonSizeToSpinnerSizeMap: Record< large: 'medium', }; -const textPadding: Record, keyof ThemeTokens['spacing']> = { +const textPadding: Record, keyof Theme['spacing']> = { xsmall: 1, small: 1, medium: 2, diff --git a/packages/blade/src/components/Button/Button/__tests__/__snapshots__/Button.native.test.tsx.snap b/packages/blade/src/components/Button/Button/__tests__/__snapshots__/Button.native.test.tsx.snap index 532457d0d67..c56ee39e204 100644 --- a/packages/blade/src/components/Button/Button/__tests__/__snapshots__/Button.native.test.tsx.snap +++ b/packages/blade/src/components/Button/Button/__tests__/__snapshots__/Button.native.test.tsx.snap @@ -89,7 +89,7 @@ exports[`