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

Refactor(Popover): move files into folder, add storybook and e2e tests. #3135

Merged
merged 4 commits into from
Apr 11, 2023
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.
2 changes: 1 addition & 1 deletion docs/content/Popover.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ status: Alpha
source: https://github.com/primer/react/blob/main/src/Popover.tsx
---

import data from '../../src/Popover.docs.json'
import data from '../../src/Popover/Popover.docs.json'

```js
import {Popover} from '@primer/react'
Expand Down
61 changes: 61 additions & 0 deletions e2e/components/Popover.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import {test, expect} from '@playwright/test'
import {visit} from '../test-helpers/storybook'
import {themes} from '../test-helpers/themes'

test.describe('Popover', () => {
test.describe('Default', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'components-popover--default',
globals: {
colorScheme: theme,
},
})

// Default state
expect(await page.screenshot()).toMatchSnapshot(`Popover.Default.${theme}.png`)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'components-popover--default',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations()
})
})
}
})

test.describe('Playground', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'components-popover--playground',
globals: {
colorScheme: theme,
},
})

// Default state
expect(await page.screenshot()).toMatchSnapshot(`Popover.Playground.${theme}.png`)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'components-popover--playground',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations()
})
})
}
})
})
113 changes: 59 additions & 54 deletions generated/components.json
Original file line number Diff line number Diff line change
Expand Up @@ -208,60 +208,6 @@
],
"subcomponents": []
},
"popover": {
"id": "popover",
"name": "Popover",
"status": "alpha",
"a11yReviewed": false,
"stories": [],
"props": [
{
"name": "as",
"type": "string",
"defaultValue": "div",
"description": "Sets the underlying HTML tag for the component"
},
{
"name": "caret",
"type": "| 'top' | 'bottom' | 'left' | 'right' | 'bottom-left' | 'bottom-right' | 'top-left' | 'top-right' | 'left-bottom' | 'left-top' | 'right-bottom' | 'right-top' ",
"defaultValue": "'top'",
"description": "Controls the position of the caret"
},
{
"name": "open",
"type": "boolean",
"defaultValue": "false",
"description": "Controls the visibility of the popover."
},
{
"name": "relative",
"type": "boolean",
"defaultValue": "false",
"description": "Set to true to render the popover using relative positioning. "
},
{
"name": "sx",
"type": "SystemStyleObject"
}
],
"subcomponents": [
{
"name": "Popover.Content",
"props": [
{
"name": "as",
"type": "string",
"defaultValue": "div",
"description": "Sets the underlying HTML tag for the component"
},
{
"name": "sx",
"type": "SystemStyleObject"
}
]
}
]
},
"styled_octicon": {
"id": "styled_octicon",
"name": "StyledOcticon",
Expand Down Expand Up @@ -3184,6 +3130,65 @@
],
"subcomponents": []
},
"popover": {
"id": "popover",
"name": "Popover",
"status": "alpha",
"a11yReviewed": false,
"stories": [
{
"id": "components-popover--default",
"code": "() => (\n <Popover relative open={true} caret=\"top\">\n <Popover.Content\n sx={{\n marginTop: 2,\n }}\n >\n <Heading\n sx={{\n fontSize: 2,\n }}\n >\n Popover heading\n </Heading>\n <Text as=\"p\">Message about popovers</Text>\n <Button>Got it!</Button>\n </Popover.Content>\n </Popover>\n)"
}
],
"props": [
{
"name": "as",
"type": "string",
"defaultValue": "div",
"description": "Sets the underlying HTML tag for the component"
},
{
"name": "caret",
"type": "| 'top' | 'bottom' | 'left' | 'right' | 'bottom-left' | 'bottom-right' | 'top-left' | 'top-right' | 'left-bottom' | 'left-top' | 'right-bottom' | 'right-top' ",
"defaultValue": "'top'",
"description": "Controls the position of the caret"
},
{
"name": "open",
"type": "boolean",
"defaultValue": "false",
"description": "Controls the visibility of the popover."
},
{
"name": "relative",
"type": "boolean",
"defaultValue": "false",
"description": "Set to true to render the popover using relative positioning. "
},
{
"name": "sx",
"type": "SystemStyleObject"
}
],
"subcomponents": [
{
"name": "Popover.Content",
"props": [
{
"name": "as",
"type": "string",
"defaultValue": "div",
"description": "Sets the underlying HTML tag for the component"
},
{
"name": "sx",
"type": "SystemStyleObject"
}
]
}
]
},
"portal": {
"id": "portal",
"name": "Portal",
Expand Down
15 changes: 15 additions & 0 deletions script/generate-e2e-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,21 @@ const components = new Map([
],
},
],
[
'Popover',
{
stories: [
{
id: 'components-popover--default',
name: 'Default',
},
{
id: 'components-popover--playground',
name: 'Playground',
},
],
},
],
[
'ProgressBar',
{
Expand Down
File renamed without changes.
69 changes: 69 additions & 0 deletions src/Popover/Popover.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import React from 'react'
import {Meta, ComponentStory} from '@storybook/react'
import Heading from '../Heading'
import Popover from './Popover'
import Text from '../Text'
import {Button} from '../Button'

export default {
title: 'Components/Popover',
component: Popover,
} as Meta<typeof Popover>

export const Default = () => (
<Popover relative open={true} caret="top">
<Popover.Content sx={{marginTop: 2}}>
<Heading sx={{fontSize: 2}}>Popover heading</Heading>
<Text as="p">Message about popovers</Text>
<Button>Got it!</Button>
</Popover.Content>
</Popover>
)

export const Playground: ComponentStory<typeof Popover> = args => (
<Popover {...args}>
<Popover.Content sx={{marginTop: 2}}>
<Heading sx={{fontSize: 2}}>Popover heading</Heading>
<Text as="p">Message about popovers</Text>
<Button>Got it!</Button>
</Popover.Content>
</Popover>
)

Playground.args = {
caret: 'top',
open: true,
relative: true,
}

Playground.argTypes = {
caret: {
control: {
type: 'radio',
},
options: [
'top',
'bottom',
'left',
'right',
'bottom-left',
'bottom-right',
'top-left',
'top-right',
'left-bottom',
'left-top',
'right-bottom',
'right-top',
],
},
open: {
control: {
type: 'boolean',
},
},
relative: {
control: {
type: 'boolean',
},
},
}
6 changes: 3 additions & 3 deletions src/Popover.tsx → src/Popover/Popover.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import classnames from 'classnames'
import styled from 'styled-components'
import {get} from './constants'
import sx, {SxProp} from './sx'
import {ComponentProps} from './utils/types'
import {get} from '../constants'
import sx, {SxProp} from '../sx'
import {ComponentProps} from '../utils/types'

type CaretPosition =
| 'top'
Expand Down
1 change: 1 addition & 0 deletions src/Popover/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {default, PopoverProps, PopoverContentProps} from './Popover'