-
Notifications
You must be signed in to change notification settings - Fork 66
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
LG-4760: Code
minimal copy button
#2661
LG-4760: Code
minimal copy button
#2661
Conversation
… into LG-4760/code-copy-button
@@ -0,0 +1,11 @@ | |||
const _baseQuery = (size: number) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was copied from the select component
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it worth replacing this in Select
in this body of work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
packages/code/src/Code.stories.tsx
Outdated
panel: undefined, | ||
}, | ||
], | ||
storyNames: ['Generated', 'MinimalCopyButton'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the optimal way to organize the generated stories? My understanding is that if we specify custom storyNames
that 'Generated'
should not be used in favor of more specific sections. However, I do see that we do that for InputOption.stories.tsx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got more context as I read further down. What do you think about calling these 'WithPanel
and WithoutPanel
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'll update the story names
packages/code/src/Code/Code.spec.tsx
Outdated
@@ -637,6 +686,7 @@ describe('packages/Code', () => { | |||
showLineNumbers={true} | |||
onCopy={() => {}} | |||
darkMode={true} | |||
copyButtonAppearance="hover" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From reading the changeset/readme, I would expect attempting to pass in copyButtonAppearance
when panel
is defined would result in a TS error or vice-versa. Should those types use a discriminated union?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that makes a lot of sense; I'll update that
hasPanel, | ||
showExpandButton, | ||
}: { | ||
scrollState: ScrollState; | ||
theme: Theme; | ||
showPanel: boolean; | ||
hasPanel: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const showPanel = !!panel || shouldRenderTempPanelSubComponent;
showPanel
seems to better align with the value getting passed in over hasPanel
what's the reason for renaming to hasPanel
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't remember, but I don't feel strongly about hasPanel
. I'll switch it back.
packages/code/src/Code/Code.tsx
Outdated
{!showPanel && | ||
copyButtonAppearance !== CopyButtonAppearance.None && | ||
ClipboardJS.isSupported() && ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: move to variable to declutter the JSX
<CopyButton onCopy={onCopy} contents={children} /> | ||
</div> | ||
)} | ||
|
||
{!!panel && panel} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be using showPanel
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, showPanel
is true if there is a panel or if a temp panel should render because of deprecated props. The panel should only render if the consumer passes it. I updated showPanel
to showPanelOrTempPanel
to hopefully clarify that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh now I see that there are 2 panels! It might be more explicit to rename the old one DeprecatedPanel
and then update the associated variables to *DeprecatedPanel
packages/code/src/Code/Code.tsx
Outdated
<div | ||
className={getCopyButtonWithoutPanelStyles({ | ||
copyButtonAppearance, | ||
})} | ||
> | ||
<CopyButton onCopy={onCopy} contents={children} /> | ||
</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe could remove a <div>
here by passing className
directly to CopyButton
?
packages/code/src/Code/Code.types.ts
Outdated
@@ -52,6 +61,21 @@ export type CodeProps = Omit< | |||
|
|||
language: Language | LanguageOption['displayName']; | |||
|
|||
/** | |||
* Determines the appearance of the copy button if the panel prop is not defined. If `panel` is defined, this prop will be ignored. The copy button allows the code block to be copied to the user's clipboard by clicking the button. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After reading this note again, I'm more convinced that copyButtonAppearance
and panel
should be a discriminated union type unless there's a specific reason to avoid that approach
@@ -0,0 +1,11 @@ | |||
const _baseQuery = (size: number) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it worth replacing this in Select
in this body of work?
@@ -242,12 +225,22 @@ export const WithDeprecatedCopyableProps: StoryType< | |||
<Code | |||
{...(args as CodeProps)} | |||
highlightLines={highlightLines ? [6, [10, 15]] : undefined} | |||
copyable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this story still be using the deprecated copyable
prop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You know, probably not. I'll remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some docs worth updating to match the new panel
| copyButtonAppearance
api but overall LGTM!
I do also still see that tooltip notch issue but that can be addressed in a separate PR if you'd like
|
||
{/* @ts-expect-error - cannot pass both panel and copyButtonAppearance */} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! 🥳
@@ -22,6 +24,28 @@ or | |||
```js | |||
panel={<Panel/>} | |||
``` | |||
|
|||
### `copyButtonAppearance` | |||
Adds a new prop, `copyButtonAppearance`. This prop determines the appearance of the copy button if the `panel` prop is not defined. If `panel` is defined, this prop will be ignored. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we update this language to better communicate only 1 or the other can be defined?
.changeset/chatty-ears-exercise.md
Outdated
Adds a new slot prop, `panel`, that accepts the new `<Panel/>` sub-component. This will render the top panel with a language switcher, custom action buttons, and copy button. If no props are passed to the panel sub-component, the panel will render with only the copy button. | ||
### `panel` | ||
|
||
Adds a new slot prop, `panel`, that accepts the new `<Panel/>` sub-component. This will render the top panel with a language switcher, custom action buttons, and copy button. If no props are passed to the panel sub-component, the panel will render with only the copy button. This prop takes precedence over `copyButtonAppearance`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we update this language to better communicate only 1 or the other can be defined?
packages/code/README.md
Outdated
| `copyButtonAppearance` | `'none'`, `'hover'`, `'persist'` | Determines the appearance of the copy button if the panel prop is not defined. If `panel` is defined, this prop will be ignored. The copy button allows the code block to be copied to the user's clipboard by clicking the button. If `hover`, the copy button will only appear when the user hovers over the code block. On mobile devices, the copy button will always be visible. If `persist`, the copy button will always be visible. If `none`, the copy button will not be rendered. | `hover` | | ||
| `panel` | `React.ReactNode` | Slot to pass the `<Panel/>` sub-component which will render the top panel with a language switcher, custom action buttons, and copy button. If no props are passed to the panel sub-component, the panel will render with only the copy button. This prop takes precedence over `copyButtonAppearance`. | `` | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we update this language to better communicate only 1 or the other can be defined?
packages/code/src/Code/Code.types.ts
Outdated
panel?: never; | ||
} | ||
| { | ||
copyButtonAppearance?: never; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: if you want the tsdoc description tooltip to show the associated comment, you'll need to include it on these props. It's not sophisticated enough for discriminated union types unless you have another vscode extension. If you hover the panel
variable, you should see that the comment doesn't show up
<CopyButton onCopy={onCopy} contents={children} /> | ||
</div> | ||
)} | ||
|
||
{!!panel && panel} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh now I see that there are 2 panels! It might be more explicit to rename the old one DeprecatedPanel
and then update the associated variables to *DeprecatedPanel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
had a note about the tooltip notch styles which are working great but could use some final cleanup before merging :)
.changeset/chatty-ears-exercise.md
Outdated
|
||
Adds a new slot prop, `panel`, that accepts the new `<Panel/>` sub-component. This will render the top panel with a language switcher, custom action buttons, and copy button. If no props are passed to the panel sub-component, the panel will render with only the copy button. | ||
|
||
**_Note: This prop takes precedence over `copyButtonAppearance`. Either use `copyButtonAppearance` or `panel`, not both._** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could just be me, but the mentions of "... takes precedence over..." + "this prop will be ignored" seem to suggest a consumer could define both if they wanted to although now with the discriminated union they should only be able to define one or the other
Simplifying the language to something like "x cannot be used with y" + "y cannot be used with x" reads more straightforward to me. Overall, I'm good with these as they are and will leave it up to you!
div[role='tooltip'] svg { | ||
width: 26px; | ||
height: 26px; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we move this into tooltipStyles
on L6? or if it needs to be defined here, can we remove tooltipStyles
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh whoops, i forgot to remove tooltipStyles
b0053aa
into
LG-4657-code-improvements-integration
✍️ Proposed changes
🎟 Jira ticket: LG-4760.
This PR adds a new minimal copy button.
Before:
After:
✅ Checklist
For bug fixes, new features & breaking changes
pnpm changeset
and documented my changesFor new components
🧪 How to test changes