-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
feat(ui): Storybook – more global components & content for typography page #28680
Conversation
1. Added global components to Storybook, in `docs-ui/components`: - Code: a component for custom code samples, and a new icon file (in `app/icons/iconCode.tsx`) - Sample: a visual wrapper for component examples - Table: styled table rows and cells - TableOfContents: an interactive table of contents that highlights sections as users scroll through docs pages 2. Added content to the Typography page. This includes 2 files, both in `docs-ui/stories/core`: `typography.stories.mdx`, and `typography.tsx`. The latter stores type definitions and exports table components for view in the docs page.
docs-ui/components/code.tsx
Outdated
import {Theme} from 'app/utils/theme'; | ||
|
||
type Props = { | ||
theme: Theme; |
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.
Do you have prettier enabled? Looks like you're using tabs instead of spaces here. Prettier should automatically fix this for you.
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.
Yeah, but there's always some code editor conflicts with my other projects. Fixing this prompto
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.
Are you using VSCode? There should be some way to have configuration per project with 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.
Sublime Text. There's a plugin called EditorConfig that could fix this, but it requires adding a .editorconfig file to the project, which sounds annoying cause I have to ignore it for every commit
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 could always add it to your personal global gitignore :) https://medium.com/@peter_graham/how-to-create-a-local-gitignore-1b19f083492b
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.
woah learn something new every day 🌈
To avoid duplicate selector warning from stylelint.
docs-ui/components/code.tsx
Outdated
|
||
type State = {}; | ||
|
||
class Code extends Component<Props, State> { |
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 these be written with functional components + hooks now?
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.
Yepp, will update it.
Initially wrote this with the intention to add some interactive features that will require a state. But it seems that many of those features are already available in Storybook preview.
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 can also easily do state using hooks these days! useState
/** | ||
* Main code content gets passed as the children prop | ||
*/ | ||
children: string; |
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 React.ReactNode
so it could be a bit more flexible?
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 point. Just tried inserting some non-text elements as children, and Prism converted all of them into plain text (Hello becomes 'Hello'), so I don't expect people to do this. Still, we should probably use React.ReactNode
to account for when they do.
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 might make some other parts of typing harder. So I would be OK requiring it to be a string
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.
Now that I see what this is doing, I think it's OK
docs-ui/components/code.tsx
Outdated
function copyCode() { | ||
const copyButton = copyButtonRef?.current; | ||
|
||
if (copyButton) { |
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 could inverse this condition and make it a guard statement, which would reduce a level of indentation :)
function copyCode() {
const copyButton = copyButtonRef?.current;
if (!copyButton) {
return
}
...
}
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.
Ahh that does look nicer!
docs-ui/components/code.tsx
Outdated
|
||
copy(copiableContent); | ||
|
||
copyButton.innerText = 'Copied'; |
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.
Would it be better to have a useState({text, disabled})
and have a setState
call here to update. Instead of digging into the DOM like this
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're right :) Fixing it
docs-ui/components/code.tsx
Outdated
<HighlightedCode className={className} ref={codeRef}> | ||
{children} | ||
</HighlightedCode> | ||
<CopyButton ref={copyButtonRef} onClick={() => copyCode()}> |
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 need for the call wrapping, this can just be onClick={copyCode}
. I might even suggest renaming copyCode
to handleCopyCode
export default withTheme(Code); | ||
|
||
const Wrap = styled('pre')` | ||
/** Increase specificity to override default styles */ |
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 hack
docs-ui/components/colorChip.tsx
Outdated
}; | ||
|
||
type WrapperProps = { | ||
large: 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.
Would a size
prop be more appropriate as like size="md"
or size="lg"
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.
Considered that but thought that since there are only two sizes, a boolean might work better. Could just use size
instead if it doesn't make too much sense for you.
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.
The reason I might suggest size, is in the case where we add more. Just gives that extra bit of flexability
.storybook/preview.tsx
Outdated
import ColorChip from '../docs-ui/components/colorChip'; | ||
import DocsLinks from '../docs-ui/components/docsLinks'; | ||
import DoDont from '../docs-ui/components/doDont'; | ||
import Sample from '../docs-ui/components/sample'; | ||
import TableOfContents from '../docs-ui/components/tableOfContents'; |
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.
btw I added the docs-ui/...
alias in webpack, so these could just be import ... from 'docs-ui/...'
.
Might look marginally better
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 I left a comment on your PR about how you used three dots (.../docs-ui
) instead of two. Was waiting for you to fix it before using the alias. My bad for not following up on this earlier 😄
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 just fix it in this PR
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.
ohhhhhh lol that's my bad
margin-bottom: ${space(1)}; | ||
`; | ||
|
||
class TableOfContents extends 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.
Let's use a functional component here. The tocbot
can be init in useEffect
docs-ui/stories/core/typography.tsx
Outdated
|
||
type TypeDefinition = { | ||
name: string; | ||
/** HTML tag (h1, h2, p) used to render type element */ |
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.
Let's keep it as a normal flag
/**
* HTML tag (h1, h2, p) used to render type element
*/
docs-ui/stories/core/typography.tsx
Outdated
/** Generic component with variable HTML tag name, | ||
* to be used with @emotion's as prop. | ||
* See: https://emotion.sh/docs/styled#as-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.
comment problems
static/app/icons/iconCode.tsx
Outdated
|
||
type Props = React.ComponentProps<typeof SvgIcon>; | ||
|
||
const IconCode = React.forwardRef(function IconChat( |
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 IconCode = React.forwardRef(function IconChat( | |
const IconCode = React.forwardRef(function IconCode( |
<path d="M3.82 12.3a.79.79 0 0 1-.53-.22l-3-3.05a.74.74 0 0 1 0-1.06l3-3a.75.75 0 0 1 1.06 1.01L1.84 8.5l2.51 2.52a.75.75 0 0 1-.53 1.28ZM12.18 12.3a.75.75 0 0 1-.53-1.28l2.51-2.52-2.51-2.52a.75.75 0 1 1 1.06-1.06l3 3.05a.741.741 0 0 1 0 1.06l-3 3.05a.79.79 0 0 1-.53.22ZM5.69 14.25A.75.75 0 0 1 5 13.19l4.62-10a.75.75 0 0 1 1-.36.74.74 0 0 1 .36 1l-4.62 10a.76.76 0 0 1-.67.42Z" /> | ||
</SvgIcon> | ||
); | ||
}); |
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.
For some reason I thought we already had this 🤔
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.
Me too! But I looked all over the place, including the list in Storybook, but couldn't find something like this 🤔
@@ -14759,6 +14759,11 @@ to-regex@^3.0.1, to-regex@^3.0.2: | |||
regex-not "^1.0.2" | |||
safe-regex "^1.1.0" | |||
|
|||
tocbot@^4.13.4: |
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.
Glad this doesn't come with much baggage
Apparently the SVG attributes I pasted into IconCode was not vertically aligned (about 1px off) 🤭 Just fixed this now. |
docs-ui/components/code.tsx
Outdated
return; | ||
} | ||
|
||
/** Remove comments from code */ |
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.
Avoid using flag comments unless they are multi-line, and are documenting something like a function or module level variable
Can just be
// Remove comments from code
docs-ui/components/code.tsx
Outdated
const [copied, setCopied] = useState(false); | ||
|
||
function handleCopyCode() { | ||
const copyButton = copyButtonRef?.current; |
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.
Do you still need this copyButtonRef?
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 right, no I don't :)
/gcbrun |
1 similar comment
/gcbrun |
1. Added more global components to Storybook (in
docs-ui/components
):app/icons/iconCode.tsx
)2. Added content to the Typography page
This includes 2 files, both in
docs-ui/stories/core
:typography.stories.mdx
, andtypography.tsx
. The latter stores type definitions and exports table components for view in the docs page.