Skip to content

Commit 7d344dc

Browse files
authored
Add play/pause button to IDE component (#1101)
* removed showReplayButton prop * implementation * bugfixes * fix broken animation * test animation behaviour * add changeset * remove unused imports * fix incorrect copilot suggestion animation * update snapshots * use borderRadius token * regen snapshots * revert changes to IDE content * wrap onPlayPause in useCallback * test that animations can be resumed * move PlayPauseButton to end of file
1 parent 30d9f1f commit 7d344dc

File tree

51 files changed

+792
-230
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+792
-230
lines changed

.changeset/brown-donkeys-beg.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@primer/react-brand': minor
3+
---
4+
5+
Added play/pause control to the `IDE` component.
6+
7+
Removed the `showReplayButton` prop as the play/pause control replaces its functionality, and is always visible.

apps/next-docs/content/components/IDE/index.mdx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ The `IDE` does not automatically apply syntax highlighting to code snippets. Usa
3131
```jsx live
3232
<IDE height={500}>
3333
<IDE.Editor
34-
showReplayButton={false}
3534
files={[
3635
{
3736
name: 'index.js',
@@ -212,7 +211,6 @@ When using the `glass` variant, pay close attention to the background image behi
212211
>
213212
<IDE height={400} variant="glass">
214213
<IDE.Editor
215-
showReplayButton={false}
216214
files={[
217215
{
218216
name: 'index.js',
@@ -283,7 +281,6 @@ In both cases, the goal is to provide a meaningful summary of the content that w
283281
| `showLineNumbers` | `boolean` | | `false` | Show line numbers in the editor |
284282
| `size` | <IDEEditorSizeProp /> | | `false` | Controls editor text size |
285283
| `triggerAnimation` | `boolean` | | `false` | Trigger animation externally |
286-
| `showReplayButton` | `boolean` | | `false` | Show replay button |
287284

288285
Supported file extensions in the editor include: <IDEFileExtensionsList />
289286

packages/design-tokens/src/tokens/functional/components/ide/colors.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,15 @@ module.exports = {
106106
dark: 'var(--base-color-scale-gray-5)',
107107
},
108108
},
109+
playPauseControl: {
110+
rest: {
111+
value: 'var(--base-color-scale-gray-2)',
112+
dark: '#4d4e6a',
113+
},
114+
hover: {
115+
value: 'var(--base-color-scale-gray-3)',
116+
dark: '#5a5b7c',
117+
},
118+
},
109119
},
110120
}

packages/react/src/IDE/IDE.features.stories.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,13 @@ export const EditorOnly = args => {
5959
)
6060
}
6161

62-
export const EditorNoReplayButton = args => {
63-
return (
64-
<IDE {...args}>
65-
<IDE.Editor size="large" activeTab={0} files={files} showReplayButton={false} />
66-
</IDE>
67-
)
68-
}
69-
70-
EditorNoReplayButton.storyName = 'Editor Only (no replay button)'
71-
7262
export const EditorCustomIcons = args => {
7363
return (
7464
<IDE {...args}>
7565
<IDE.Editor
7666
size="large"
7767
activeTab={0}
7868
files={files}
79-
showReplayButton={false}
8069
tabIcons={{
8170
...Object.keys(IDEDefaultIconMap).reduce((acc, key) => {
8271
acc[key] = 'https://github.com/primer/brand/assets/13340707/fede56eb-578f-4d17-b045-5f6fdfae28cf'
@@ -88,8 +77,6 @@ export const EditorCustomIcons = args => {
8877
)
8978
}
9079

91-
EditorNoReplayButton.storyName = 'Editor Only (no replay button)'
92-
9380
export const ChatOnly = args => {
9481
return (
9582
<IDE {...args}>
@@ -238,7 +225,7 @@ PerspectiveExampleLight.decorators = [
238225
export const AllGlass = args => (
239226
<IDE {...args} variant="glass">
240227
<IDE.Chat script={chatScript} alternativeText={chatScriptAlt}></IDE.Chat>
241-
<IDE.Editor size="large" files={files} showReplayButton={false} />
228+
<IDE.Editor size="large" files={files} />
242229
</IDE>
243230
)
244231

packages/react/src/IDE/IDE.module.css

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -377,17 +377,52 @@ pre.IDE__Chat-copilot-indicator {
377377
fill: var(--brand-IDE-autoSuggest-fgColor);
378378
}
379379

380-
.IDE__Editor-replay {
381-
margin-block-start: var(--base-size-24);
382-
margin-block-end: var(--base-size-16);
383-
align-self: center;
384-
position: relative;
385-
z-index: 1;
380+
.IDE__play-pause-button {
381+
cursor: pointer;
382+
position: absolute;
383+
bottom: var(--base-size-16);
384+
right: var(--base-size-16);
385+
display: flex;
386+
align-items: center;
387+
justify-content: center;
388+
width: var(--base-size-48);
389+
height: var(--base-size-48);
390+
margin: 0;
391+
padding: 0;
392+
border: none;
393+
border-radius: var(--brand-borderRadius-full);
394+
background-color: var(--brand-IDE-playPauseControl-rest);
395+
transition: background-color var(--brand-animation-duration-faster);
386396
}
387397

388-
.IDE__Editor-replay[disabled] {
389-
opacity: 0.5;
390-
cursor: not-allowed;
398+
.IDE__play-pause-button:hover {
399+
background-color: var(--brand-IDE-playPauseControl-hover);
400+
}
401+
402+
.IDE__play-pause-button:focus-visible {
403+
outline: var(--base-size-4) solid var(--brand-color-focus);
404+
outline-offset: var(--base-size-2);
405+
}
406+
407+
.IDE__play-pause-button svg {
408+
width: var(--base-size-16);
409+
height: var(--base-size-16);
410+
}
411+
412+
.IDE__play-pause-button path {
413+
fill: var(--brand-button-subtle-fgColor-rest);
414+
}
415+
416+
.IDE--chat-only .IDE__Chat-input-area {
417+
width: calc(100% - var(--base-size-64));
418+
}
419+
420+
.IDE--chat-only .IDE__play-pause-button {
421+
background-color: var(--brand-IDE-playPauseControl-rest);
422+
}
423+
424+
.IDE--chat-only .IDE__play-pause-button:hover {
425+
background-color: var(--brand-IDE-playPauseControl-hover);
391426
}
392427

393428
/* Remove all animations, transitions and smooth scroll for people that prefer not to see them */

packages/react/src/IDE/IDE.module.css.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
declare const styles: {
22
readonly "IDE": string;
3+
readonly "IDE--chat-only": string;
34
readonly "IDE--default": string;
45
readonly "IDE--full-exp": string;
56
readonly "IDE--glass": string;
@@ -28,14 +29,14 @@ declare const styles: {
2829
readonly "IDE__Editor-lineNumbers": string;
2930
readonly "IDE__Editor-pane": string;
3031
readonly "IDE__Editor-pane--suggested": string;
31-
readonly "IDE__Editor-replay": string;
3232
readonly "IDE__Editor-tab": string;
3333
readonly "IDE__Editor-tab--active": string;
3434
readonly "IDE__Editor-tab-close-icon": string;
3535
readonly "IDE__Editor-tab-icon": string;
3636
readonly "IDE__Editor-tabs": string;
3737
readonly "IDE__inner": string;
3838
readonly "IDE__main": string;
39+
readonly "IDE__play-pause-button": string;
3940
};
4041
export = styles;
4142

packages/react/src/IDE/IDE.stories.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export default {
2727
args: {
2828
showChat: true,
2929
height: 800,
30-
showReplayButton: false,
3130
},
3231
argTypes: {
3332
showChat: {
@@ -43,13 +42,6 @@ export default {
4342
control: {
4443
type: 'number',
4544
},
46-
showReplayButton: {
47-
name: 'show replay button',
48-
description: 'toggle replay button visibility',
49-
control: {
50-
type: 'boolean',
51-
},
52-
},
5345
},
5446
className: {table: {disable: true}},
5547
id: {table: {disable: true}},
@@ -74,15 +66,14 @@ export default {
7466

7567
type StoryProps = {
7668
showChat: boolean
77-
showReplayButton: boolean
7869
height: number
7970
} & IDEProps
8071

81-
const Template: StoryFn<StoryProps> = ({showChat, showReplayButton, ...args}) => {
72+
const Template: StoryFn<StoryProps> = ({showChat, ...args}) => {
8273
return (
8374
<IDE {...args}>
8475
{showChat && <IDE.Chat script={chatScript} alternativeText={chatScriptAlt}></IDE.Chat>}
85-
<IDE.Editor files={defaultFiles} showReplayButton={showReplayButton} />
76+
<IDE.Editor files={defaultFiles} />
8677
</IDE>
8778
)
8879
}

0 commit comments

Comments
 (0)