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

Adds UnderlinePanels to drafts/ #4550

Merged
merged 37 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
4a27922
adds UnderlinePanels components and stories
mperrotti May 1, 2024
393afbb
Merge branch 'main' of github.com:primer/react into mp/underline-panels
mperrotti May 2, 2024
e9ac50c
adds tests, minor stylistic updates
mperrotti May 2, 2024
c05ac21
adds component docs
mperrotti May 2, 2024
5eef15a
adds changeset
mperrotti May 2, 2024
7c00947
corrects changeset
mperrotti May 2, 2024
0a87590
fixes circ dep, tests, misc bugs
mperrotti May 3, 2024
9eda952
more test fixes
mperrotti May 3, 2024
8b9c328
appease the linter
mperrotti May 3, 2024
f6a2067
updates snaps, fixes tiny visual regression
mperrotti May 3, 2024
8197cc0
test(vrt): update snapshots
mperrotti May 3, 2024
81b478c
cleanup
mperrotti May 9, 2024
b600b34
upgrades @github/tab-container-element
mperrotti May 9, 2024
b2f6daa
Merge branch 'main' into mp/underline-panels
mperrotti May 9, 2024
fa3f238
fixes createComponent import
mperrotti May 9, 2024
711fed0
updates jest snapshots
mperrotti May 9, 2024
1f2e1a9
Apply suggestion from @broccolinisoup
mperrotti May 13, 2024
047bfad
addresses PR feedback
mperrotti May 14, 2024
a2f0995
Merge branch 'main' of github.com:primer/react into mp/underline-panels
mperrotti May 14, 2024
f728a01
Merge branch 'main' into mp/underline-panels
mperrotti May 15, 2024
7091c99
fix broken import
mperrotti May 15, 2024
ec55b9f
Merge branch 'main' of github.com:primer/react into mp/underline-panels
mperrotti May 21, 2024
38e98ed
addresses more PR feedback
mperrotti May 21, 2024
426f8c0
Merge branch 'main' into mp/underline-panels
mperrotti May 21, 2024
0f0b58c
test(vrt): update snapshots
mperrotti May 21, 2024
86d5ef9
Merge branch 'main' of github.com:primer/react into mp/underline-panels
mperrotti Jun 12, 2024
4dac206
Merge branch 'mp/underline-panels' of github.com:primer/react into mp…
mperrotti Jun 12, 2024
9d7e5d7
Merge branch 'main' into mp/underline-panels
mperrotti Jun 13, 2024
66e1ada
test(vrt): update snapshots
mperrotti Jun 13, 2024
efa5386
Merge branch 'main' of github.com:primer/react into mp/underline-panels
mperrotti Jun 17, 2024
c601277
Merge branch 'mp/underline-panels' of github.com:primer/react into mp…
mperrotti Jun 17, 2024
13ad02a
Merge branch 'main' into mp/underline-panels
mperrotti Jun 17, 2024
43bb92e
adds fallbacks to CSS vars
mperrotti Jun 18, 2024
6db2049
Merge branch 'main' of github.com:primer/react into mp/underline-panels
mperrotti Jun 18, 2024
c55b637
fixes CSS typo
mperrotti Jun 18, 2024
744eb62
fixes more typos
mperrotti Jun 18, 2024
1cbc162
Merge branch 'main' into mp/underline-panels
mperrotti Jun 18, 2024
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
Prev Previous commit
Next Next commit
adds component docs
  • Loading branch information
mperrotti committed May 2, 2024
commit c05ac214d1d322f1c13f4752b120ac7b77ce7ed5
4 changes: 2 additions & 2 deletions packages/react/src/UnderlineNav/UnderlineNav.docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"importPath": "@primer/react",
"props": [
{
"name": "afterSelect",
"name": "onSelect",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh must have forgotten to update this, thank you!

"type": "(event) => void",
"defaultValue": "",
"description": "The handler that gets called when a nav link child is selected"
Expand Down Expand Up @@ -48,7 +48,7 @@
},
{
"name": "counter",
"type": "number",
"type": "number | string",
"defaultValue": "",
"description": "The number to display in the counter label."
},
Expand Down
104 changes: 104 additions & 0 deletions packages/react/src/drafts/UnderlinePanels/UnderlinePanels.docs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"id": "underline_panels",
"name": "UnderlinePanels",
"status": "draft",
"a11yReviewed": false,
"stories": [
{
"id": "drafts-components-underlinepanels--default"
},
{
"id": "'drafts-components-underlinepanels-features--labelled-by-external-element"
},
{
"id": "drafts-components-underlinepanels-features--selected-tab"
},
{
"id": "drafts-components-underlinepanels-features--with-counters"
},
{
"id": "drafts-components-underlinepanels-features--with-counters-in-loading-state"
},
{
"id": "drafts-components-underlinepanels-features--with-icons"
},
{
"id": "drafts-components-underlinepanels-features--with-icons-hidden-on-narrow-screen"
}
],
"importPath": "@primer/react",
"props": [
{
"name": "aria-label",
"type": "string",
"defaultValue": "",
"description": "Accessible name for the tab list"
},
{
"name": "aria-labelledby",
"type": "string",
"defaultValue": "",
"description": "ID of the element containing the name for the tab list"
},
{
"name": "children",
"type": "Array<UnderlinePanels.Tab | UnderlinePanels.Panel>",
"defaultValue": "",
"required": true,
"description": "Tabs (UnderlinePanels.Tab) and panels (UnderlinePanels.Panel) to render"
},
{
"name": "id",
"type": "string",
"defaultValue": "",
"description": "Custom string to use when generating the IDs of tabs and `aria-labelledby` for the panels"
},
{
"name": "loadingCounters",
"type": "boolean",
"defaultValue": "false",
"description": "Loading state for all counters. It displays loading animation for individual counters until all are resolved. It is needed to prevent multiple layout shift."
},
{
"name": "sx",
"type": "SystemStyleObject"
}
],
"subcomponents": [
{
"name": "UnderlinePanels.Tab",
"props": [
{
"name": "aria-selected",
"type": "| boolean | 'true' | 'false'",
"defaultValue": "false",
"description": "Whether this is the selected tab. For more information about `aria-current`, see [MDN](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-selected)."
},
{
"name": "counter",
"type": "number | string",
"defaultValue": "",
"description": "Content of CounterLabel rendered after tab text label"
},
{
"name": "icon",
"type": "Component",
"defaultValue": "",
"description": "Icon rendered before the tab text label"
},
{
"name": "sx",
"type": "SystemStyleObject"
}
]
},
{
"name": "UnderlinePanels.Tab",
"props": [],
"passthrough": {
"element": "div",
"url": "https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div#Attributes"
}
}
]
}
24 changes: 22 additions & 2 deletions packages/react/src/drafts/UnderlinePanels/UnderlinePanels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
useRef,
type FC,
type PropsWithChildren,
useLayoutEffect,

Check failure on line 9 in packages/react/src/drafts/UnderlinePanels/UnderlinePanels.tsx

View workflow job for this annotation

GitHub Actions / lint

'useLayoutEffect' import from 'react' is restricted. Please use the `useIsomorphicLayoutEffect` hook from `src/hooks/useIsomorphicLayoutEffect.ts` instead
} from 'react'
import {TabContainerElement} from '@github/tab-container-element'
import createComponent from '../../utils/custom-element'
Expand All @@ -28,17 +28,37 @@
* Whether this is the selected tab
*/
'aria-selected'?: boolean
/**
* Content of CounterLabel rendered after tab text label
*/
counter?: number | string
/**
* Icon rendered before the tab text label
*/
icon?: FC<IconProps>
} & SxProp

type UnderlineTabbedInterfaceProps = {
/**
* Tabs (UnderlinePanels.Tab) and panels (UnderlinePanels.Panel) to render
*/
children: React.ReactNode
/**
* Accessible name for the tab list
*/
'aria-label'?: React.AriaAttributes['aria-label']
/**
* ID of the element containing the name for the tab list
*/
'aria-labelledby'?: React.AriaAttributes['aria-labelledby']
as?: React.ElementType
loadingCounters?: boolean
/**
* Custom string to use when generating the IDs of tabs and `aria-labelledby` for the panels
*/
id?: string
/**
* Loading state for all counters. It displays loading animation for individual counters until all are resolved. It is needed to prevent multiple layout shift.
*/
loadingCounters?: boolean
} & SxProp

const TabContainerComponent = createComponent(TabContainerElement, 'tab-container')
Expand Down Expand Up @@ -93,7 +113,7 @@
}

setListWidth(listRef.current?.getBoundingClientRect().width ?? 0)
}, [])

Check failure on line 116 in packages/react/src/drafts/UnderlinePanels/UnderlinePanels.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useLayoutEffect has a missing dependency: 'tabsHaveIcons'. Either include it or remove the dependency array

// when the wrapper resizes, check if the icons should be visible
// by comparing the wrapper width to the list width
Expand All @@ -119,8 +139,8 @@

// every tab has its panel
invariant(
tabs.current?.length === tabPanels.current?.length,

Check failure on line 142 in packages/react/src/drafts/UnderlinePanels/UnderlinePanels.tsx

View workflow job for this annotation

GitHub Actions / lint

Unnecessary optional chain on a non-nullish value

Check failure on line 142 in packages/react/src/drafts/UnderlinePanels/UnderlinePanels.tsx

View workflow job for this annotation

GitHub Actions / lint

Unnecessary optional chain on a non-nullish value
`The number of tabs and panels must be equal. Counted ${tabs.current?.length} tabs and ${tabPanels.current?.length} panels.`,

Check failure on line 143 in packages/react/src/drafts/UnderlinePanels/UnderlinePanels.tsx

View workflow job for this annotation

GitHub Actions / lint

Unnecessary optional chain on a non-nullish value

Check failure on line 143 in packages/react/src/drafts/UnderlinePanels/UnderlinePanels.tsx

View workflow job for this annotation

GitHub Actions / lint

Unnecessary optional chain on a non-nullish value
)
}

Expand Down
Loading