-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[polaris.shopify.com] Include HTML source for examples #6688
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
Changes from 19 commits
98b6bbc
6196272
675e3ca
a6b3aae
510fd2e
0b3bd78
42fa893
a99a605
72109a1
bce992c
b10dac4
467e6a6
41397ed
cba2ffb
29953db
a252b7a
5b8edf2
929da6b
9fcdf0a
68d2694
ea746ca
14d50e8
d14db48
27fcb14
4b68771
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 @@ | ||
| --- | ||
| 'polaris.shopify.com': minor | ||
| --- | ||
|
|
||
| Simplify rendering of code blocks on site. Use the same component for every code example. This makes the experience more consistent and ensures that every code block has features like copy paste. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| @import "../../styles/mixins.scss"; | ||
|
|
||
| .Code { | ||
| border-radius: var(--border-radius-400); | ||
| max-width: calc(100vw - 1.5rem); | ||
| cursor: text; | ||
| background: var(--surface); | ||
| color: var(--text-strong); | ||
| box-shadow: var(--card-shadow); | ||
| } | ||
|
|
||
| .TopBar { | ||
| display: flex; | ||
| justify-content: space-between; | ||
| align-items: center; | ||
| border-bottom: 1px solid var(--border-color-light); | ||
| } | ||
|
|
||
| .Tabs { | ||
| padding-left: 1rem; | ||
| display: flex; | ||
|
|
||
| .Tab { | ||
| padding-top: 0.66rem; | ||
| padding-bottom: 0.66rem; | ||
| border-radius: var(--border-radius-300); | ||
| background: transparent; | ||
| font-size: var(--font-size-100); | ||
| color: var(--text-subdued); | ||
| } | ||
|
|
||
| button.Tab { | ||
| padding-left: 0.5rem; | ||
| padding-right: 0.5rem; | ||
| color: var(--text-strong); | ||
|
|
||
| &[aria-selected="true"] { | ||
| position: relative; | ||
|
|
||
| &:not(:focus-visible) { | ||
| &:after { | ||
| content: ""; | ||
| display: block; | ||
| position: absolute; | ||
| right: 0; | ||
| bottom: 0; | ||
| left: 0; | ||
| background: var(--text-strong); | ||
| height: 3px; | ||
| border-radius: var(--border-radius-200) var(--border-radius-200) 0 0; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| &:focus-visible { | ||
| box-shadow: var(--focus-outline); | ||
| } | ||
| } | ||
|
|
||
| .CopyButton { | ||
| padding: 0.5rem 1rem; | ||
| background: transparent; | ||
| border-radius: var(--border-radius-200); | ||
| opacity: 0.5; | ||
| display: flex; | ||
| align-items: center; | ||
|
|
||
| &:hover, | ||
| &:focus { | ||
| opacity: 1; | ||
| } | ||
|
|
||
| svg { | ||
| width: 16px; | ||
| height: 16px; | ||
| } | ||
|
|
||
| &:focus-visible { | ||
| box-shadow: none; | ||
| opacity: 1; | ||
| } | ||
| } | ||
|
|
||
| .ActualCode { | ||
| font-family: var(--font-family-mono); | ||
| white-space: pre-wrap; | ||
| padding: 0.85rem 1rem; | ||
| font-size: 14px; | ||
| line-height: 1.6; | ||
| overflow: auto; | ||
| max-height: 50vh; | ||
|
|
||
| @include custom-scrollbars; | ||
| } | ||
|
|
||
| .LineNumber { | ||
| display: none; | ||
| opacity: 0.5; | ||
| margin-right: 0.5rem; | ||
| user-select: none; | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,98 @@ | ||||||
| import Tooltip from "../Tooltip"; | ||||||
| import Prism from "prismjs"; | ||||||
| import { useCopyToClipboard } from "../../utils/hooks"; | ||||||
| import styles from "./Code.module.scss"; | ||||||
| import { Tab } from "@headlessui/react"; | ||||||
| import Image from "../Image"; | ||||||
| import { useState } from "react"; | ||||||
|
|
||||||
| interface Props { | ||||||
| tabs: { | ||||||
|
||||||
| tabs: { | |
| tabs?: { |
Outdated
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.
When I first read the PR description I assumed that the Code component was a generic wrapper for any code sample on the site, but it looks like it's specific to ComponentExamples. Should we move the sub-component into a components directory inside of the ComponentExamples directory? Can the component be more generic, maybe the tabs prop could be optional? For example, rendering the Code component for the /contributing/shipping-your-contribution code page doesn't completely translate for things like yarn commands.
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.
It is generic! Is there anything about it that made you think otherwise?
The tabs are optional — if you pass in a single example, Code will render it without tabs.
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 we just have two components? CodeTabs and CodeBlock or something? We kind of already do with HighlightedCode.
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 clarified the component props a bit which maybe (?) makes the component clearer:
To render some code:
<Code code={{ title: "My example", code }} />
To render multiple pieces of code:
<Code code={[
{ title: "Styles", code: cssCode },
{ title: "HTML", code: htmlCode },
]} />
In short: It's not about the tabs, it's about what you want to render. The tabs are just a happy side effect.
Happy to refactor this down the road if it causes confusion!
Outdated
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 should probably be pre instead of 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? It seems like prism does some stuff...
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.
Good catch! Fixed!
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import Code from "./Code"; | ||
|
|
||
| export default Code; |
This file was deleted.
This file was deleted.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.