-
Notifications
You must be signed in to change notification settings - Fork 561
refactor(styles): diff view and code theme on shared tokens #8069
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
Merged
+327
−149
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e28c7f9
refactor(styles): drop the .dark override in the code theme
talissoncosta 38f4d99
refactor(styles): diff view on the shared code tokens
talissoncosta 6e80ddc
test(storybook): add DiffString stories
talissoncosta 91b88b3
fix(storybook): stop docs code styling repainting rendered stories
talissoncosta 920bf46
refactor(styles): name the diff's two strengths as local custom prope…
talissoncosta 246719d
fix(styles): put the plain-text value editor on the input surface token
talissoncosta 9fdd248
feat(diff): add DiffRow for the rows we build ourselves
talissoncosta b24fd26
fix(diff): restore the added and removed colours on boolean rows
talissoncosta a16ca0e
refactor(diff): give DiffFeature's header legend its own stylesheet
talissoncosta 0c80b53
fix(storybook): keep component code surfaces in dark docs
talissoncosta b0cb8ff
refactor(storybook): group the diff stories under Components/Diff
talissoncosta b31cff2
refactor(diff): trim the comments and leave the stories unsnapshotted
talissoncosta d526093
refactor(diff): use the token and Bootstrap utilities where they exist
talissoncosta 14cb99a
refactor(diff): drop two declarations that never applied
talissoncosta 606de0d
fix(storybook): keep hljs colours in light docs too
talissoncosta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import type { Meta, StoryObj } from 'storybook' | ||
|
|
||
| import DiffEnabled from 'components/diff/DiffEnabled' | ||
|
|
||
| const meta: Meta<typeof DiffEnabled> = { | ||
| component: DiffEnabled, | ||
| parameters: { | ||
| docs: { | ||
| description: { | ||
| component: | ||
| 'The diff view for a flag or segment override being turned on or off.', | ||
| }, | ||
| }, | ||
| layout: 'padded', | ||
| }, | ||
| title: 'Components/Diff/DiffEnabled', | ||
| } | ||
|
|
||
| export default meta | ||
|
|
||
| type Story = StoryObj<typeof DiffEnabled> | ||
|
|
||
| export const OffToOn: Story = { | ||
| args: { newValue: true, oldValue: false }, | ||
| } | ||
|
|
||
| export const OnToOff: Story = { | ||
| args: { newValue: false, oldValue: true }, | ||
| } | ||
|
|
||
| export const Unchanged: Story = { | ||
| args: { newValue: true, oldValue: true }, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import type { Meta, StoryObj } from 'storybook' | ||
|
|
||
| import DiffRow from 'components/diff/DiffRow' | ||
|
|
||
| const meta: Meta<typeof DiffRow> = { | ||
| component: DiffRow, | ||
| parameters: { | ||
| docs: { | ||
| description: { | ||
| component: | ||
| 'One row of a diff: a marker cell beside the content that changed. ' + | ||
| 'Used by DiffEnabled and DiffString for the rows we build ourselves.', | ||
| }, | ||
| }, | ||
| layout: 'padded', | ||
| }, | ||
| title: 'Components/Diff/DiffRow', | ||
| } | ||
|
|
||
| export default meta | ||
|
|
||
| type Story = StoryObj<typeof DiffRow> | ||
|
|
||
| export const Removed: Story = { | ||
| args: { children: 'banner_size: small', state: 'removed' }, | ||
| } | ||
|
|
||
| export const Added: Story = { | ||
| args: { children: 'banner_size: large', state: 'added' }, | ||
| } | ||
|
|
||
| export const Unchanged: Story = { | ||
| args: { children: 'banner_size: large', state: 'unchanged' }, | ||
| } | ||
|
|
||
| export const Stacked: Story = { | ||
| render: () => ( | ||
| <> | ||
| <DiffRow state='removed'>banner_size: small</DiffRow> | ||
| <DiffRow state='added'>banner_size: large</DiffRow> | ||
| </> | ||
| ), | ||
| } | ||
|
|
||
| export const LongContentScrolls: Story = { | ||
| args: { | ||
| children: 'banner_size: '.repeat(40), | ||
| scrollable: true, | ||
| state: 'unchanged', | ||
| }, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import type { Meta, StoryObj } from 'storybook' | ||
|
|
||
| import DiffString from 'components/diff/DiffString' | ||
|
|
||
| const meta: Meta<typeof DiffString> = { | ||
| component: DiffString, | ||
| parameters: { | ||
| docs: { | ||
| description: { | ||
| component: | ||
| 'The diff view for flag values (react-diff-viewer + Prism for JSON). ' + | ||
| 'Uses the same code colour tokens as the Highlight component, so it ' + | ||
| 'follows light/dark mode. Toggle the theme in the toolbar to QA.', | ||
| }, | ||
| }, | ||
| layout: 'padded', | ||
| }, | ||
| title: 'Components/Diff/DiffString', | ||
| } | ||
|
|
||
| export default meta | ||
|
|
||
| type Story = StoryObj<typeof DiffString> | ||
|
|
||
| const oldJson = `{ | ||
| "id": "london-js", | ||
| "title": "Hello London.js!", | ||
| "description": "Join us at London.js and get insights on best practices!", | ||
| "buttonText": "Register on Meetup", | ||
| "isClosable": false | ||
| }` | ||
|
|
||
| const newJson = `{ | ||
| "id": "london-js", | ||
| "title": "Hello London.js!", | ||
| "description": "Join us at London.js!", | ||
| "buttonText": "Register now", | ||
| "isClosable": true | ||
| }` | ||
|
|
||
| export const ChangedJson: Story = { | ||
| args: { newValue: newJson, oldValue: oldJson }, | ||
| } | ||
|
|
||
| export const ChangedString: Story = { | ||
| args: { newValue: 'banner_size: large', oldValue: 'banner_size: small' }, | ||
| } | ||
|
|
||
| export const SameJson: Story = { | ||
| args: { newValue: oldJson, oldValue: oldJson }, | ||
| } | ||
|
|
||
| // An empty old value renders as `""`, not a blank row. | ||
| export const FromEmpty: Story = { | ||
| args: { newValue: 'banner_size: large', oldValue: '' }, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| .diff-header { | ||
| font-size: 13px; | ||
| font-weight: 500; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // _react-diff.scss repeats these two values for the library's own rows. | ||
| .diff-row { | ||
| --diff-row-removed: oklch(from var(--red-500) l c h / 0.16); | ||
| --diff-row-added: oklch(from var(--green-500) l c h / 0.16); | ||
|
|
||
| line-height: 31px; | ||
|
|
||
| &__marker { | ||
| width: 31px; | ||
| height: 31px; | ||
| background-color: var(--color-surface-subtle); | ||
|
|
||
| > * { | ||
| margin: 0; | ||
| } | ||
| } | ||
|
|
||
| &__content { | ||
| flex: 1; | ||
| min-width: 0; | ||
| padding-right: 0.5rem; | ||
|
|
||
| .rc-switch { | ||
| margin-bottom: 2px; | ||
| } | ||
| } | ||
|
|
||
| &--removed { | ||
| .diff-row__marker, | ||
| .diff-row__content { | ||
| background-color: var(--diff-row-removed); | ||
| } | ||
| } | ||
|
|
||
| &--added { | ||
| .diff-row__marker, | ||
| .diff-row__content { | ||
| background-color: var(--diff-row-added); | ||
| } | ||
| } | ||
|
|
||
| &--unchanged { | ||
| background-color: var(--color-surface-subtle); | ||
| font-size: 13px; | ||
|
|
||
| .diff-row__marker { | ||
| opacity: 0; | ||
| } | ||
|
|
||
| .diff-row__content { | ||
| padding-right: 0; | ||
|
|
||
| pre { | ||
| padding-left: 2px; | ||
| background-color: var(--color-surface-subtle); | ||
| font-family: var(--bs-font-monospace); | ||
| font-size: 13px; | ||
| line-height: 28px; | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import React, { FC, ReactNode } from 'react' | ||
| import classNames from 'classnames' | ||
| import './DiffRow.scss' | ||
|
|
||
| export type DiffRowState = 'added' | 'removed' | 'unchanged' | ||
|
|
||
| type DiffRowProps = { | ||
| state: DiffRowState | ||
| children: ReactNode | ||
| // Scroll long content rather than widening the container. | ||
| scrollable?: boolean | ||
| className?: string | ||
| } | ||
|
|
||
| const MARKERS: Record<DiffRowState, string> = { | ||
| added: '+', | ||
| removed: '-', | ||
| unchanged: '', | ||
| } | ||
|
|
||
| const DiffRow: FC<DiffRowProps> = ({ | ||
| children, | ||
| className, | ||
| scrollable, | ||
| state, | ||
| }) => ( | ||
| <div | ||
| className={classNames( | ||
| 'diff-row d-flex align-items-center', | ||
| `diff-row--${state}`, | ||
| className, | ||
| { 'overflow-auto': scrollable }, | ||
| )} | ||
| > | ||
| <div className='diff-row__marker d-flex align-items-center justify-content-center flex-shrink-0'> | ||
| <pre>{MARKERS[state]}</pre> | ||
| </div> | ||
| <div className='diff-row__content'>{children}</div> | ||
| </div> | ||
| ) | ||
|
|
||
| export default DiffRow |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export { default } from './DiffRow' | ||
| export type { DiffRowState } from './DiffRow' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.