Skip to content
Merged
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -5,98 +5,98 @@ import {themes} from '../../test-helpers/themes'
const variants = [
{
title: 'Default',
id: 'drafts-components-label--default',
id: 'drafts-components-issuelabel--default',
},
{
title: 'Auburn',
id: 'drafts-components-label-features--auburn',
id: 'drafts-components-issuelabel-features--auburn',
},
{
title: 'Blue',
id: 'drafts-components-label-features--blue',
id: 'drafts-components-issuelabel-features--blue',
},
{
title: 'Brown',
id: 'drafts-components-label-features--brown',
id: 'drafts-components-issuelabel-features--brown',
},
{
title: 'Coral',
id: 'drafts-components-label-features--coral',
id: 'drafts-components-issuelabel-features--coral',
},
{
title: 'Cyan',
id: 'drafts-components-label-features--cyan',
id: 'drafts-components-issuelabel-features--cyan',
},
{
title: 'Gray',
id: 'drafts-components-label-features--gray',
id: 'drafts-components-issuelabel-features--gray',
},
{
title: 'Green',
id: 'drafts-components-label-features--green',
id: 'drafts-components-issuelabel-features--green',
},
{
title: 'Indigo',
id: 'drafts-components-label-features--indigo',
id: 'drafts-components-issuelabel-features--indigo',
},
{
title: 'Lemon',
id: 'drafts-components-label-features--lemon',
id: 'drafts-components-issuelabel-features--lemon',
},
{
title: 'Lime',
id: 'drafts-components-label-features--lime',
id: 'drafts-components-issuelabel-features--lime',
},
{
title: 'Olive',
id: 'drafts-components-label-features--olive',
id: 'drafts-components-issuelabel-features--olive',
},
{
title: 'Orange',
id: 'drafts-components-label-features--orange',
id: 'drafts-components-issuelabel-features--orange',
},
{
title: 'Pine',
id: 'drafts-components-label-features--pine',
id: 'drafts-components-issuelabel-features--pine',
},
{
title: 'Pink',
id: 'drafts-components-label-features--pink',
id: 'drafts-components-issuelabel-features--pink',
},
{
title: 'Plum',
id: 'drafts-components-label-features--plum',
id: 'drafts-components-issuelabel-features--plum',
},
{
title: 'Purple',
id: 'drafts-components-label-features--purple',
id: 'drafts-components-issuelabel-features--purple',
},
{
title: 'Red',
id: 'drafts-components-label-features--red',
id: 'drafts-components-issuelabel-features--red',
},
{
title: 'Teal',
id: 'drafts-components-label-features--teal',
id: 'drafts-components-issuelabel-features--teal',
},
{
title: 'Yellow',
id: 'drafts-components-label-features--yellow',
id: 'drafts-components-issuelabel-features--yellow',
},
] as const

const sizes = [
{
title: 'Size: Large',
id: 'drafts-components-label-features--size-large',
id: 'drafts-components-issuelabel-features--size-large',
},
{
title: 'Size: Small',
id: 'drafts-components-label-features--size-small',
id: 'drafts-components-issuelabel-features--size-small',
},
] as const

test.describe('Label', () => {
test.describe('IssueLabel', () => {
for (const story of variants) {
test.describe(story.title, () => {
for (const theme of themes) {
Expand All @@ -115,7 +115,7 @@ test.describe('Label', () => {
})

// Default state
expect(await page.screenshot()).toMatchSnapshot(`Label.${story.title}.${theme}.png`)
expect(await page.screenshot()).toMatchSnapshot(`IssueLabel.${story.title}.${theme}.png`)
})

test('axe @aat', async ({page}) => {
Expand Down Expand Up @@ -145,7 +145,7 @@ test.describe('Label', () => {
})

// Default state
expect(await page.screenshot()).toMatchSnapshot(`Label.${story.title}.png`)
expect(await page.screenshot()).toMatchSnapshot(`IssueLabel.${story.title}.png`)
})

test('axe @aat', async ({page}) => {
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
"focus-visible": "^5.2.0",
"fzy.js": "^0.4.1",
"history": "^5.0.0",
"hsluv": "1.0.1",
"lodash.isempty": "^4.4.0",
"lodash.isobject": "^3.0.2",
"react-intersection-observer": "^9.4.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ exports[`@primer/react/drafts should not update exports without a semver change
"InlineAutocomplete",
"type InlineAutocompleteProps",
"type InteractiveMarkdownViewerProps",
"IssueLabel",
"type IssueLabelProps",
"MarkdownEditor",
"type MarkdownEditorHandle",
"type MarkdownEditorProps",
Expand Down Expand Up @@ -366,6 +368,8 @@ exports[`@primer/react/experimental should not update exports without a semver c
"InlineAutocomplete",
"type InlineAutocompleteProps",
"type InteractiveMarkdownViewerProps",
"IssueLabel",
"type IssueLabelProps",
"MarkdownEditor",
"type MarkdownEditorHandle",
"type MarkdownEditorProps",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'
import {IssueLabel} from '../IssueLabel'
import type {Meta} from '@storybook/react'
import type {Hex} from './IssueLabel'

const meta = {
title: 'Drafts/Components/IssueLabel/Features',
Expand Down Expand Up @@ -51,12 +52,12 @@ export const SizeLarge = () => <IssueLabel size="large">Issue label</IssueLabel>

export const SizeSmall = () => <IssueLabel size="small">Issue label</IssueLabel>

export const Hex = hex => <IssueLabel fillColor={hex}>Issue label</IssueLabel>
Hex.args = {
export const HexColor = (hex: Hex) => <IssueLabel fillColor={hex}>Issue label</IssueLabel>
HexColor.args = {
hex: '#59B200',
variant: undefined,
}
Hex.argTypes = {
HexColor.argTypes = {
hex: {control: {type: 'color'}},
variant: {control: {disable: true}},
}
6 changes: 5 additions & 1 deletion packages/react/src/drafts/IssueLabel/IssueLabel.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {IssueLabel} from '../IssueLabel'
import type {Meta, StoryObj} from '@storybook/react'

const meta = {
title: 'Drafts/Components/Label',
title: 'Drafts/Components/IssueLabel',
component: IssueLabel,
} satisfies Meta<typeof IssueLabel>

Expand All @@ -15,6 +15,10 @@ export const Playground: StoryObj<typeof IssueLabel> = {
render: args => <IssueLabel {...args}>Issue label</IssueLabel>,
args: {},
argTypes: {
fillColor: {
hex: undefined,
control: {type: 'color', presetColors: ['red', 'green', 'blue', 'brown', 'black', 'white', 'salmon', 'orange']},
},
size: {
control: 'select',
option: ['small', 'large'],
Expand Down
20 changes: 18 additions & 2 deletions packages/react/src/drafts/IssueLabel/IssueLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React from 'react'
import styled from 'styled-components'
import {get} from '../../constants'
import {getColorsFromHex} from './getColorFromHex'
import {useTheme} from '../../ThemeProvider'
export type Hex = `#${string}`

type LabelColorVariant =
| 'pink'
Expand Down Expand Up @@ -29,7 +32,7 @@ export interface IssueLabelProps extends React.PropsWithChildren {
/**
*
*/
fillColor?: string
fillColor?: Hex

/**
*
Expand All @@ -43,8 +46,21 @@ export interface IssueLabelProps extends React.PropsWithChildren {
}

export function IssueLabel({children, fillColor, size = 'small', variant = 'gray', ...rest}: IssueLabelProps) {
const {resolvedColorScheme} = useTheme()
const mode = resolvedColorScheme?.startsWith('dark') ? 'dark' : 'light'
// TODO: get the bgColor, getting it from theme.colorScheme seems a bit sketchy
const bgColors: Record<string, Hex> = {
light: '#ffffff',
dark: '#0d1117',
}

return (
<StyledLabel {...rest} data-size={size} data-variant={fillColor ? undefined : variant}>
<StyledLabel
{...rest}
data-size={size}
data-variant={fillColor ? undefined : variant}
style={fillColor ? getColorsFromHex(fillColor, resolvedColorScheme, bgColors[mode]) : undefined}
>
{children}
</StyledLabel>
)
Expand Down
Loading