diff --git a/.changeset/gold-cups-explode.md b/.changeset/gold-cups-explode.md new file mode 100644 index 00000000000..535886b6912 --- /dev/null +++ b/.changeset/gold-cups-explode.md @@ -0,0 +1,5 @@ +--- +"@primer/react": minor +--- + +Add `size` and `weight` props to `Text` diff --git a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-dark-colorblind-linux.png b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-dark-colorblind-linux.png deleted file mode 100644 index efc61f7680f..00000000000 Binary files a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-dark-colorblind-linux.png and /dev/null differ diff --git a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-dark-high-contrast-linux.png b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-dark-high-contrast-linux.png deleted file mode 100644 index cae82e0704e..00000000000 Binary files a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-dark-high-contrast-linux.png and /dev/null differ diff --git a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-dark-linux.png b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-dark-linux.png deleted file mode 100644 index efc61f7680f..00000000000 Binary files a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-dark-linux.png and /dev/null differ diff --git a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-dark-tritanopia-linux.png b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-dark-tritanopia-linux.png deleted file mode 100644 index efc61f7680f..00000000000 Binary files a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-dark-tritanopia-linux.png and /dev/null differ diff --git a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Playground-light-linux.png b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-linux.png similarity index 61% rename from .playwright/snapshots/components/Text.test.ts-snapshots/Text-Playground-light-linux.png rename to .playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-linux.png index 0248fe6dd3e..19185243bd8 100644 Binary files a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Playground-light-linux.png and b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-linux.png differ diff --git a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-dark-dimmed-linux.png b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Large-linux.png similarity index 61% rename from .playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-dark-dimmed-linux.png rename to .playwright/snapshots/components/Text.test.ts-snapshots/Text-Large-linux.png index c75bd69eda4..d037ee600a1 100644 Binary files a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-dark-dimmed-linux.png and b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Large-linux.png differ diff --git a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Playground-dark-high-contrast-linux.png b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Light-linux.png similarity index 60% rename from .playwright/snapshots/components/Text.test.ts-snapshots/Text-Playground-dark-high-contrast-linux.png rename to .playwright/snapshots/components/Text.test.ts-snapshots/Text-Light-linux.png index 5579c83df90..d037ee600a1 100644 Binary files a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Playground-dark-high-contrast-linux.png and b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Light-linux.png differ diff --git a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-light-high-contrast-linux.png b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-LightWeight-linux.png similarity index 59% rename from .playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-light-high-contrast-linux.png rename to .playwright/snapshots/components/Text.test.ts-snapshots/Text-LightWeight-linux.png index 276f325d57a..d037ee600a1 100644 Binary files a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-light-high-contrast-linux.png and b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-LightWeight-linux.png differ diff --git a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Playground-light-high-contrast-linux.png b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Medium-linux.png similarity index 64% rename from .playwright/snapshots/components/Text.test.ts-snapshots/Text-Playground-light-high-contrast-linux.png rename to .playwright/snapshots/components/Text.test.ts-snapshots/Text-Medium-linux.png index eb914d84f4b..5a7357f3279 100644 Binary files a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Playground-light-high-contrast-linux.png and b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Medium-linux.png differ diff --git a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-light-linux.png b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-MediumWeight-linux.png similarity index 59% rename from .playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-light-linux.png rename to .playwright/snapshots/components/Text.test.ts-snapshots/Text-MediumWeight-linux.png index 3d347d677ff..d037ee600a1 100644 Binary files a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-light-linux.png and b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-MediumWeight-linux.png differ diff --git a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Normal-linux.png b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Normal-linux.png new file mode 100644 index 00000000000..d037ee600a1 Binary files /dev/null and b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Normal-linux.png differ diff --git a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-NormalWeight-linux.png b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-NormalWeight-linux.png new file mode 100644 index 00000000000..d037ee600a1 Binary files /dev/null and b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-NormalWeight-linux.png differ diff --git a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Playground-dark-colorblind-linux.png b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Playground-dark-colorblind-linux.png deleted file mode 100644 index cf61e376458..00000000000 Binary files a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Playground-dark-colorblind-linux.png and /dev/null differ diff --git a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Playground-dark-dimmed-linux.png b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Playground-dark-dimmed-linux.png deleted file mode 100644 index f430c4da66c..00000000000 Binary files a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Playground-dark-dimmed-linux.png and /dev/null differ diff --git a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Playground-dark-linux.png b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Playground-dark-linux.png deleted file mode 100644 index cf61e376458..00000000000 Binary files a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Playground-dark-linux.png and /dev/null differ diff --git a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Playground-dark-tritanopia-linux.png b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Playground-dark-tritanopia-linux.png deleted file mode 100644 index cf61e376458..00000000000 Binary files a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Playground-dark-tritanopia-linux.png and /dev/null differ diff --git a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Playground-light-colorblind-linux.png b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Playground-light-colorblind-linux.png deleted file mode 100644 index 6687bd8ce30..00000000000 Binary files a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Playground-light-colorblind-linux.png and /dev/null differ diff --git a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Playground-light-tritanopia-linux.png b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Playground-light-tritanopia-linux.png deleted file mode 100644 index 6687bd8ce30..00000000000 Binary files a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Playground-light-tritanopia-linux.png and /dev/null differ diff --git a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-light-tritanopia-linux.png b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Semibold-linux.png similarity index 61% rename from .playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-light-tritanopia-linux.png rename to .playwright/snapshots/components/Text.test.ts-snapshots/Text-Semibold-linux.png index 6c4d519f029..6fcee4fa33a 100644 Binary files a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-light-tritanopia-linux.png and b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Semibold-linux.png differ diff --git a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-light-colorblind-linux.png b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-SemiboldWeight-linux.png similarity index 61% rename from .playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-light-colorblind-linux.png rename to .playwright/snapshots/components/Text.test.ts-snapshots/Text-SemiboldWeight-linux.png index 6c4d519f029..6fcee4fa33a 100644 Binary files a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Default-light-colorblind-linux.png and b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-SemiboldWeight-linux.png differ diff --git a/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Small-linux.png b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Small-linux.png new file mode 100644 index 00000000000..a013812b95e Binary files /dev/null and b/.playwright/snapshots/components/Text.test.ts-snapshots/Text-Small-linux.png differ diff --git a/e2e/components/Text.test.ts b/e2e/components/Text.test.ts index 952eb5f17bf..031a4adf876 100644 --- a/e2e/components/Text.test.ts +++ b/e2e/components/Text.test.ts @@ -1,61 +1,61 @@ import {test, expect} from '@playwright/test' import {visit} from '../test-helpers/storybook' -import {themes} from '../test-helpers/themes' -test.describe('Text', () => { - test.describe('Default', () => { - for (const theme of themes) { - test.describe(theme, () => { - test('default @vrt', async ({page}) => { - await visit(page, { - id: 'components-text--default', - globals: { - colorScheme: theme, - }, - }) +const stories = [ + { + title: 'Default', + id: 'components-text--default', + }, + { + title: 'Small', + id: 'components-text-features--size-small', + }, + { + title: 'Medium', + id: 'components-text-features--size-medium', + }, + { + title: 'Large', + id: 'components-text-features--size-large', + }, + { + title: 'LightWeight', + id: 'components-text-features--light-weight', + }, + { + title: 'NormalWeight', + id: 'components-text-features--normal-weight', + }, + { + title: 'MediumWeight', + id: 'components-text-features--medium-weight', + }, + { + title: 'SemiboldWeight', + id: 'components-text-features--semibold-weight', + }, +] as const - // Default state - expect(await page.screenshot()).toMatchSnapshot(`Text.Default.${theme}.png`) - }) +// only testing light theme because this component is only concerned with text size and weight - test('axe @aat', async ({page}) => { - await visit(page, { - id: 'components-text--default', - globals: { - colorScheme: theme, - }, - }) - await expect(page).toHaveNoViolations() +test.describe('Text', () => { + for (const story of stories) { + test.describe(story.title, () => { + test('default @vrt', async ({page}) => { + await visit(page, { + id: story.id, }) - }) - } - }) - test.describe('Playground', () => { - for (const theme of themes) { - test.describe(theme, () => { - test('default @vrt', async ({page}) => { - await visit(page, { - id: 'components-text--playground', - globals: { - colorScheme: theme, - }, - }) - - // Default state - expect(await page.screenshot()).toMatchSnapshot(`Text.Playground.${theme}.png`) - }) + // Default state + expect(await page.screenshot()).toMatchSnapshot(`Text.${story.title}.png`) + }) - test('axe @aat', async ({page}) => { - await visit(page, { - id: 'components-text--playground', - globals: { - colorScheme: theme, - }, - }) - await expect(page).toHaveNoViolations() + test('axe @aat', async ({page}) => { + await visit(page, { + id: story.id, }) + await expect(page).toHaveNoViolations() }) - } - }) + }) + } }) diff --git a/package-lock.json b/package-lock.json index 44f9e461428..1d353e01dd9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -292,7 +292,7 @@ "name": "example-app-router", "version": "0.0.0", "dependencies": { - "@primer/react": "36.27.0", + "@primer/react": "37.0.0-rc.0", "next": "^14.1.0", "react": "^18.3.1", "react-dom": "^18.3.1", @@ -311,7 +311,7 @@ "react-dom": "^18.3.1" }, "devDependencies": { - "@primer/react": "36.27.0", + "@primer/react": "37.0.0-rc.0", "@types/react": "^18.3.3", "@types/react-dom": "^18.3.0", "@typescript-eslint/eslint-plugin": "^7.11.0", @@ -329,7 +329,7 @@ "name": "example-consumer-test", "version": "0.0.0", "dependencies": { - "@primer/react": "*", + "@primer/react": "37.0.0-rc.0", "@types/react": "^18.2.14", "@types/react-dom": "^18.2.19", "@types/styled-components": "^5.1.11", @@ -355,7 +355,7 @@ "version": "0.0.0", "dependencies": { "@primer/octicons-react": "19.x", - "@primer/react": "36.27.0", + "@primer/react": "37.0.0-rc.0", "next": "^14.1.0", "react": "^18.3.1", "react-dom": "^18.3.1", @@ -60996,7 +60996,7 @@ }, "packages/react": { "name": "@primer/react", - "version": "36.27.0", + "version": "37.0.0-rc.0", "license": "MIT", "dependencies": { "@github/combobox-nav": "^2.1.5", diff --git a/packages/react/src/Text/Text.docs.json b/packages/react/src/Text/Text.docs.json index 4fec260b880..35e5f646c41 100644 --- a/packages/react/src/Text/Text.docs.json +++ b/packages/react/src/Text/Text.docs.json @@ -14,6 +14,14 @@ { "name": "sx", "type": "SystemStyleObject" + }, + { + "name": "size", + "type": "'large' | 'medium' | 'small'" + }, + { + "name": "weight", + "type": "'light' | 'normal' | 'medium' | 'semibold'" } ], "subcomponents": [] diff --git a/packages/react/src/Text/Text.features.stories.tsx b/packages/react/src/Text/Text.features.stories.tsx index ad91f5014fc..cd8f49e61b7 100644 --- a/packages/react/src/Text/Text.features.stories.tsx +++ b/packages/react/src/Text/Text.features.stories.tsx @@ -19,7 +19,49 @@ export const Polymorphism = () => ( ) export const StyledText = () => ( - + + Stylized text + +) + +export const SizeSmall = () => ( + + Stylized text + +) + +export const SizeMedium = () => ( + + Stylized text + +) + +export const SizeLarge = () => ( + + Stylized text + +) + +export const LightWeight = () => ( + + Stylized text + +) + +export const NormalWeight = () => ( + + Stylized text + +) + +export const MediumWeight = () => ( + + Stylized text + +) + +export const SemiboldWeight = () => ( + Stylized text ) diff --git a/packages/react/src/Text/Text.stories.tsx b/packages/react/src/Text/Text.stories.tsx index 23f40cf3d49..361b30d70b9 100644 --- a/packages/react/src/Text/Text.stories.tsx +++ b/packages/react/src/Text/Text.stories.tsx @@ -14,6 +14,8 @@ export const Playground: StoryFn = args => {args.te Playground.args = { text: 'Playground', as: 'span', + size: 'medium', + weight: 'normal', } Playground.argTypes = { @@ -29,12 +31,6 @@ Playground.argTypes = { disable: true, }, }, - theme: { - controls: false, - table: { - disable: true, - }, - }, ref: { controls: false, table: { @@ -47,4 +43,16 @@ Playground.argTypes = { disable: true, }, }, + size: { + control: { + type: 'radio', + }, + options: ['small', 'medium', 'large'], + }, + weight: { + control: { + type: 'radio', + }, + options: ['light', 'normal', 'medium', 'semibold'], + }, } diff --git a/packages/react/src/Text/Text.tsx b/packages/react/src/Text/Text.tsx index 5c71752f3da..d74320cddb8 100644 --- a/packages/react/src/Text/Text.tsx +++ b/packages/react/src/Text/Text.tsx @@ -5,11 +5,52 @@ import type {SxProp} from '../sx' import sx from '../sx' import type {ComponentProps} from '../utils/types' -const Text = styled.span` +type StyledTextProps = { + size?: 'large' | 'medium' | 'small' + weight?: 'light' | 'normal' | 'medium' | 'semibold' +} & SystemTypographyProps & + SystemCommonProps & + SxProp + +const Text = styled.span.attrs(({size, weight}) => ({ + 'data-size': size, + 'data-weight': weight, +}))` ${TYPOGRAPHY}; ${COMMON}; + + &:where([data-size='small']) { + font-size: var(--text-body-size-small, 0.75rem); + line-height: var(--text-body-lineHeight-small, 1.6666); + } + + &:where([data-size='medium']) { + font-size: var(--text-body-size-medium, 0.875rem); + line-height: var(--text-body-lineHeight-medium, 1.4285); + } + + &:where([data-size='large']) { + font-size: var(--text-body-size-large, 1rem); + line-height: var(--text-body-lineHeight-large, 1.5); + } + + &:where([data-weight='light']) { + font-weight: var(--base-text-weight-light, 300); + } + + &:where([data-weight='normal']) { + font-weight: var(--base-text-weight-normal, 400); + } + + &:where([data-weight='medium']) { + font-weight: var(--base-text-weight-medium, 500); + } + + &:where([data-weight='semibold']) { + font-weight: var(--base-text-weight-semibold, 600); + } + ${sx}; ` - export type TextProps = ComponentProps export default Text diff --git a/packages/react/src/__tests__/__snapshots__/TextInputWithTokens.test.tsx.snap b/packages/react/src/__tests__/__snapshots__/TextInputWithTokens.test.tsx.snap index 379c8e69b12..6fcb73235d6 100644 --- a/packages/react/src/__tests__/__snapshots__/TextInputWithTokens.test.tsx.snap +++ b/packages/react/src/__tests__/__snapshots__/TextInputWithTokens.test.tsx.snap @@ -831,6 +831,37 @@ exports[`TextInputWithTokens renders a truncated set of tokens 1`] = ` color: var(--fgColor-muted,var(--color-fg-muted,#656d76)); } +.c9:where([data-size='small']) { + font-size: var(--text-body-size-small,0.75rem); + line-height: var(--text-body-lineHeight-small,1.6666); +} + +.c9:where([data-size='medium']) { + font-size: var(--text-body-size-medium,0.875rem); + line-height: var(--text-body-lineHeight-medium,1.4285); +} + +.c9:where([data-size='large']) { + font-size: var(--text-body-size-large,1rem); + line-height: var(--text-body-lineHeight-large,1.5); +} + +.c9:where([data-weight='light']) { + font-weight: var(--base-text-weight-light,300); +} + +.c9:where([data-weight='normal']) { + font-weight: var(--base-text-weight-normal,400); +} + +.c9:where([data-weight='medium']) { + font-weight: var(--base-text-weight-medium,500); +} + +.c9:where([data-weight='semibold']) { + font-weight: var(--base-text-weight-semibold,600); +} + .c0 { font-size: 14px; line-height: 20px; diff --git a/packages/react/src/__tests__/__snapshots__/ThemeProvider.test.tsx.snap b/packages/react/src/__tests__/__snapshots__/ThemeProvider.test.tsx.snap index f12d32801c4..1790814dd63 100644 --- a/packages/react/src/__tests__/__snapshots__/ThemeProvider.test.tsx.snap +++ b/packages/react/src/__tests__/__snapshots__/ThemeProvider.test.tsx.snap @@ -6,6 +6,37 @@ exports[`has default theme 1`] = ` margin-bottom: 4px; } +.c0:where([data-size='small']) { + font-size: var(--text-body-size-small,0.75rem); + line-height: var(--text-body-lineHeight-small,1.6666); +} + +.c0:where([data-size='medium']) { + font-size: var(--text-body-size-medium,0.875rem); + line-height: var(--text-body-lineHeight-medium,1.4285); +} + +.c0:where([data-size='large']) { + font-size: var(--text-body-size-large,1rem); + line-height: var(--text-body-lineHeight-large,1.5); +} + +.c0:where([data-weight='light']) { + font-weight: var(--base-text-weight-light,300); +} + +.c0:where([data-weight='normal']) { + font-weight: var(--base-text-weight-normal,400); +} + +.c0:where([data-weight='medium']) { + font-weight: var(--base-text-weight-medium,500); +} + +.c0:where([data-weight='semibold']) { + font-weight: var(--base-text-weight-semibold,600); +} +