Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 677
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?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
a04b7bdaad16e8fd4ede31a980468d3071f21de126658a69b1442a2925eda48747843ccfe2bb4f74c96a9f253cc06edaec9c1881277492547397e5fa4553a21d876f4203aa28c3804a376f16c709cf7e162642f30da5d3a6f617f4File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
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 |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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 👀
|
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| 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 👀
| ||
| 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.
Uh oh!There was an error while loading. Please reload this page. | ||
| <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? MemberAuthor 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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.