-
Notifications
You must be signed in to change notification settings - Fork 668
BranchName: Add leadingVisual, trailingAction and description
#7993
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
base: main
Are you sure you want to change the base?
Changes from all commits
a04b7bd
aad16e8
fd4ede3
1a98046
8d3071f
21de126
658a69b
1442a29
25eda48
747843c
cfe2bb4
f74c96a
9f253cc
06edaec
9c18812
7749254
7397e5f
a4553a2
1d876f4
203aa28
c3804a3
76f16c7
09cf7e1
62642f3
0da5d3a
6f617f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@primer/react": minor | ||
| --- | ||
|
|
||
| BranchName: Add `LeadingVisual` and `TrailingAction` subcomponents and a `description` prop |
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. noticed some of these are displaying tooltips and some aren't, just want to make sure this doesn't become flaky vrt 👀
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I wanted to have screenshots for focus states and menu-open but it was creating too many screenshots, so I have limited interactive states to just light theme. Shouldn't be flaky in my opinion |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,10 +14,27 @@ const stories = [ | |
| focus: false, | ||
| }, | ||
| { | ||
| // Note: the story was renamed to "With Leading Visual" but we keep the | ||
| // snapshot title as "With A Branch Icon" so the VRT diff stays usable. | ||
|
Comment on lines
+17
to
+18
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. curious how this works 👀
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh i just kept the title and filename the same in e2e/Branchname.test so that I can get a snapshot diff if there is one |
||
| title: 'With A Branch Icon', | ||
| id: 'components-branchname-features--with-branch-icon', | ||
| id: 'components-branchname-features--with-leading-visual', | ||
| focus: false, | ||
| }, | ||
| { | ||
| title: 'Link Without Href', | ||
| id: 'components-branchname-features--link-without-href', | ||
| focus: true, | ||
| }, | ||
| { | ||
| title: 'No Props', | ||
| id: 'components-branchname-features--no-props', | ||
| focus: false, | ||
| }, | ||
| { | ||
| title: 'With Description', | ||
| id: 'components-branchname-features--with-description', | ||
| focus: true, | ||
| }, | ||
| { | ||
| title: 'With Trailing Action', | ||
| id: 'components-branchname-features--with-trailing-action', | ||
|
|
@@ -28,6 +45,11 @@ const stories = [ | |
| id: 'components-branchname-features--with-trailing-action-menu', | ||
| focus: false, | ||
| }, | ||
| { | ||
| title: 'Kitchen Sink', | ||
| id: 'components-branchname-features--kitchen-sink', | ||
| focus: false, | ||
| }, | ||
| ] as const | ||
|
|
||
| test.describe('BranchName', () => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,22 @@ | ||
| import type {Meta} from '@storybook/react-vite' | ||
| import React, {useState} from 'react' | ||
| import React, {useState, useRef} from 'react' | ||
| import BranchName from './BranchName' | ||
| import {Stack} from '../Stack' | ||
| import Octicon from '../Octicon' | ||
| import {GitBranchIcon, CopyIcon, CheckIcon, TriangleDownIcon} from '@primer/octicons-react' | ||
| import {IconButton} from '../Button' | ||
| import {Tooltip} from '../TooltipV2' | ||
| import {SelectPanel} from '../SelectPanel' | ||
| import type {ItemInput} from '../FilteredActionList' | ||
| import {clsx} from 'clsx' | ||
| import {announce} from '@primer/live-region-element' | ||
|
|
||
| import styles from './BranchName.stories.module.css' | ||
|
|
||
| export default { | ||
| title: 'Components/BranchName/Features', | ||
| component: BranchName, | ||
| } as Meta<typeof BranchName> | ||
|
|
||
| export const WithBranchIcon = () => ( | ||
| export const WithLeadingVisual = () => ( | ||
| <BranchName href="#"> | ||
| <Stack direction="horizontal" gap="condensed" align="center"> | ||
| <Octicon icon={GitBranchIcon} /> | ||
| branch_name | ||
| </Stack> | ||
|
francinelucca marked this conversation as resolved.
|
||
| <BranchName.LeadingVisual> | ||
| <GitBranchIcon /> | ||
| </BranchName.LeadingVisual> | ||
| branch_name | ||
| </BranchName> | ||
| ) | ||
|
|
||
|
|
@@ -38,6 +31,18 @@ export const LinkWithoutHref = () => ( | |
|
|
||
| export const NoProps = () => <BranchName>branch_name_no_props</BranchName> | ||
|
|
||
| export const WithDescription = ({ | ||
| branchName = 'fix/anchored-overlay-outside-top-autogrow', | ||
| repo = 'primer/react', | ||
| }: { | ||
| branchName: string | ||
| repo: string | ||
| }) => ( | ||
| <BranchName href={`https://github.com/${repo}/tree/${branchName}`} description={`${repo}:${branchName}`}> | ||
| {branchName} | ||
| </BranchName> | ||
| ) | ||
|
|
||
| export const WithTrailingAction = ({ | ||
| branchName = 'fix/anchored-overlay-outside-top-autogrow', | ||
| repo = 'primer/react', | ||
|
|
@@ -54,26 +59,15 @@ export const WithTrailingAction = ({ | |
| setTimeout(() => setCopied(false), 2000) | ||
| } | ||
|
|
||
| const tooltipText = copied ? 'Copied!' : 'Copy branch name to clipboard' | ||
|
|
||
| return ( | ||
| <span className={styles.BranchNameWithTrailingAction}> | ||
| <Tooltip text={`${repo}:${branchName}`}> | ||
| <BranchName href={`https://github.com/${repo}/tree/${branchName}`} className={styles.BranchNameTransparent}> | ||
| {branchName} | ||
| </BranchName> | ||
| </Tooltip> | ||
| <Tooltip text={tooltipText} aria-hidden> | ||
| <IconButton | ||
| icon={copied ? CheckIcon : CopyIcon} | ||
| aria-label="Copy branch name to clipboard" | ||
| variant="invisible" | ||
| size="small" | ||
| onClick={handleCopy} | ||
| className={clsx(styles.TrailingActionButton, copied && styles.TrailingActionButtonCopied)} | ||
| /> | ||
| </Tooltip> | ||
| </span> | ||
| <BranchName href={`https://github.com/${repo}/tree/${branchName}`} description={`${repo}:${branchName}`}> | ||
| {branchName} | ||
| <BranchName.TrailingAction | ||
| icon={copied ? CheckIcon : CopyIcon} | ||
| aria-label="Copy branch name to clipboard" | ||
| onClick={handleCopy} | ||
| /> | ||
| </BranchName> | ||
| ) | ||
| } | ||
|
|
||
|
|
@@ -94,6 +88,7 @@ export const WithTrailingActionMenu = ({repo = 'primer/react'}: {repo: string}) | |
| const [selected, setSelected] = useState<ItemInput>(branches[0]) | ||
| const [filter, setFilter] = useState('') | ||
| const [open, setOpen] = useState(false) | ||
| const anchorRef = useRef<HTMLButtonElement>(null) | ||
|
|
||
| const filteredBranches = branches.filter(branch => branch.text?.toLowerCase().includes(filter.toLowerCase())) | ||
|
|
||
|
|
@@ -104,21 +99,19 @@ export const WithTrailingActionMenu = ({repo = 'primer/react'}: {repo: string}) | |
| } | ||
|
|
||
| return ( | ||
| <span className={styles.BranchNameWithTrailingAction}> | ||
| <BranchName href={`https://github.com/${repo}/tree/${selected.text}`} className={styles.BranchNameTransparent}> | ||
|
Comment on lines
-107
to
-108
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any dead css as a result of this we can cleanup?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought I deleted the file, i had not 🤔 Thanks for catching that! |
||
| <> | ||
| <BranchName href={`https://github.com/${repo}/tree/${selected.text}`}> | ||
| {selected.text} | ||
| <BranchName.TrailingAction | ||
| icon={TriangleDownIcon} | ||
| aria-label="Change base branch" | ||
| ref={anchorRef} | ||
| onClick={() => setOpen(!open)} | ||
| /> | ||
| </BranchName> | ||
| <SelectPanel | ||
| renderAnchor={anchorProps => ( | ||
| <IconButton | ||
| icon={TriangleDownIcon} | ||
| aria-label="Change base branch" | ||
| variant="invisible" | ||
| size="small" | ||
| className={styles.TrailingActionButton} | ||
| {...anchorProps} | ||
| /> | ||
| )} | ||
| renderAnchor={null} | ||
| anchorRef={anchorRef} | ||
| placeholder="Find a branch..." | ||
| open={open} | ||
| onOpenChange={setOpen} | ||
|
|
@@ -129,6 +122,37 @@ export const WithTrailingActionMenu = ({repo = 'primer/react'}: {repo: string}) | |
| title="Change base branch" | ||
| overlayProps={{width: 'medium'}} | ||
| /> | ||
| </span> | ||
| </> | ||
| ) | ||
| } | ||
|
|
||
| export const KitchenSink = ({ | ||
| branchName = 'fix/anchored-overlay-outside-top-autogrow', | ||
| repo = 'primer/react', | ||
| }: { | ||
| branchName: string | ||
| repo: string | ||
| }) => { | ||
| const [copied, setCopied] = React.useState(false) | ||
|
|
||
| const handleCopy = () => { | ||
| setCopied(true) | ||
| void navigator.clipboard.writeText(branchName) | ||
| announce('Copied!') | ||
| setTimeout(() => setCopied(false), 2000) | ||
| } | ||
|
|
||
| return ( | ||
| <BranchName href={`https://github.com/${repo}/tree/${branchName}`} description={`${repo}:${branchName}`}> | ||
| <BranchName.LeadingVisual> | ||
| <GitBranchIcon /> | ||
| </BranchName.LeadingVisual> | ||
| {branchName} | ||
| <BranchName.TrailingAction | ||
| icon={copied ? CheckIcon : CopyIcon} | ||
| aria-label="Copy branch name to clipboard" | ||
| onClick={handleCopy} | ||
| /> | ||
| </BranchName> | ||
| ) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.