Skip to content
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

Merged
merged 8 commits into from
Sep 22, 2021

Conversation

vuluongj20
Copy link
Member

@vuluongj20 vuluongj20 commented Sep 20, 2021

1. Added more global components to Storybook (in docs-ui/components):

  • Code: a component for custom code samples, and an accompanying icon file (in app/icons/iconCode.tsx)

Screen Shot 2021-09-20 at 11 29 20 AM

  • Sample: a visual wrapper for component examples

Screen Shot 2021-09-20 at 11 29 59 AM

  • Table: styled table headers, rows and cells

Screen Shot 2021-09-20 at 11 30 23 AM

  • TableOfContents: an interactive table of contents that highlights sections as users scroll through docs pages. This gets added to DocsPages automatically.

Screen Shot 2021-09-20 at 11 30 38 AM

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.

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.
@vuluongj20 vuluongj20 requested review from a team as code owners September 20, 2021 18:28
import {Theme} from 'app/utils/theme';

type Props = {
theme: Theme;
Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member

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

Copy link
Member Author

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.
@vuluongj20 vuluongj20 changed the title Storybook: more global components & content for typography page feat(ui): Storybook – more global components & content for typography page Sep 20, 2021
@vuluongj20 vuluongj20 requested a review from billyvg September 20, 2021 19:59

type State = {};

class Code extends Component<Props, State> {
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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;
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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

Copy link
Member

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

function copyCode() {
const copyButton = copyButtonRef?.current;

if (copyButton) {
Copy link
Member

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
	}

	...
}

Copy link
Member Author

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!


copy(copiableContent);

copyButton.innerText = 'Copied';
Copy link
Member

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

Copy link
Member Author

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

<HighlightedCode className={className} ref={codeRef}>
{children}
</HighlightedCode>
<CopyButton ref={copyButtonRef} onClick={() => copyCode()}>
Copy link
Member

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 */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice hack

};

type WrapperProps = {
large: boolean;
Copy link
Member

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"

Copy link
Member Author

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.

Copy link
Member

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

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';
Copy link
Member

@evanpurkhiser evanpurkhiser Sep 21, 2021

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

Copy link
Member Author

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 😄

Copy link
Member Author

@vuluongj20 vuluongj20 Sep 21, 2021

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

Copy link
Member

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 {
Copy link
Member

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


type TypeDefinition = {
name: string;
/** HTML tag (h1, h2, p) used to render type element */
Copy link
Member

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
 */

/** Generic component with variable HTML tag name,
* to be used with @emotion's as prop.
* See: https://emotion.sh/docs/styled#as-prop
* */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment problems


type Props = React.ComponentProps<typeof SvgIcon>;

const IconCode = React.forwardRef(function IconChat(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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>
);
});
Copy link
Member

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 🤔

Copy link
Member Author

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:
Copy link
Member

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

@evanpurkhiser
Copy link
Member

image

can we get the icon center with the text?

@vuluongj20
Copy link
Member Author

Apparently the SVG attributes I pasted into IconCode was not vertically aligned (about 1px off) 🤭 Just fixed this now.
However, there is still some small misalignment due to the default baseline settings of the font face. This is not as noticeable. I'll do some further research into font face rendering and look for a way to fix it!

return;
}

/** Remove comments from code */
Copy link
Member

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

const [copied, setCopied] = useState(false);

function handleCopyCode() {
const copyButton = copyButtonRef?.current;
Copy link
Member

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?

Copy link
Member Author

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 :)

@davidenwang
Copy link
Contributor

/gcbrun

1 similar comment
@billyvg
Copy link
Member

billyvg commented Sep 22, 2021

/gcbrun

@vuluongj20 vuluongj20 merged commit 4ac0d63 into master Sep 22, 2021
@vuluongj20 vuluongj20 deleted the vuluong/storybook-content branch September 22, 2021 19:43
@github-actions github-actions bot locked and limited conversation to collaborators Oct 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants