-
Notifications
You must be signed in to change notification settings - Fork 114
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: create Code Block Package #2641
Conversation
🦋 Changeset detectedLatest commit: c4d5e48 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for paste-theme-designer ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit c4d5e48:
|
Size Change: +745 B (0%) Total Size: 759 kB
ℹ️ View Unchanged
|
✅ Deploy Preview for paste-docs ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Test summaryRun details
View run in Cypress Dashboard ➡️ This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard |
packages/paste-core/components/code-block/__tests__/index.spec.tsx
Outdated
Show resolved
Hide resolved
packages/paste-website/src/pages/components/code-block/index.mdx
Outdated
Show resolved
Hide resolved
packages/paste-website/src/pages/components/code-block/index.mdx
Outdated
Show resolved
Hide resolved
4928d7e
to
aec5a9a
Compare
packages/paste-libraries/syntax-highlighter/stories/index.stories.tsx
Outdated
Show resolved
Hide resolved
packages/paste-core/components/code-block/__tests__/index.spec.tsx
Outdated
Show resolved
Hide resolved
MozTabSize: '4', | ||
OTabSize: '4', | ||
tabSize: '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.
question: what does this translate to?
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 changes the size of the tab character: https://developer.mozilla.org/en-US/docs/Web/CSS/tab-size
11c6704
to
29ebf59
Compare
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.
thanks for this @shleewhite !
"CodeBlockTab": "@twilio-paste/core/code-block", | ||
"CodeBlockTabList": "@twilio-paste/core/code-block", | ||
"CodeBlockTabPanel": "@twilio-paste/core/code-block", | ||
"CodeBlockWrapper": "@twilio-paste/core/code-block", |
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 my own edification what do these changes in the .cache/mappings.json
file 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.
This is for a codemod that helps people transition from barreled to unbarreled imports. It is used here: https://github.com/twilio-labs/paste/blob/main/packages/paste-codemods/transforms/barreled-to-unbarreled.js to check what people are importing and change it from import {whatevs} from '@twilio-paste/whatevs'
to import {whatevs} from '@twilio-paste/core/whatevs'
@@ -0,0 +1,9 @@ | |||
declare module 'react-syntax-highlighter/dist/esm/languages/prism/shell-session' { | |||
const language: any; |
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.
minor, but this isn't 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.
@TheSisb @gloriliale do either of you have context for why this file is needed?
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.
@shleewhite typically I write an ambient module declaration like this when a 3rd party package doesn't ship with its own type annotations or a type repository like DefinitelyTyped doesn't have community types available. That all said my guess is that this package react-syntax-highlighter
was missing some types so we added them. Going a bit further to my original question, generally we'd want to avoid any
types if possible, even preferring something like unknown
if we don't have time to determine which type it should be.
if (variant !== 'primary' && variant !== 'secondary' && variant !== 'reset') { | ||
throw new Error(`[Paste: Button] <Button as="a"> only works with the following variants: primary or secondary.`); | ||
if (variant !== 'primary' && variant !== 'secondary' && variant !== 'reset' && variant !== 'inverse') { | ||
throw new Error(`[Paste: Button] <Button as="a"> only works with the following variants: primary and secondary.`); |
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.
its interesting that we include usage enforcement code like this as part of the run time! One thing we might explore in the future is handling this kind of thing through dev time only type annotations or react propTypes! cc @TheSisb
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.
Totally.. I don't have full context here but I think we usually try to do this stuff with types/propTypes, but for really important things we actually throw errors. We throw errors in Avatar and Badge too.
export const CopyButton: React.FC<CopyButtonProps> = ({ | ||
text, | ||
i18nCopyLabelBefore = 'Copy code block', | ||
i18nCopyLabelAfter = '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.
oh are these english strings default values? we don't worry about I18n english leaks like this to allow for a more minimal default API perhaps?
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.
Can you clarify what you mean by i18n english leaks?
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 just that for products that are internationalized, when a developer does not provide a translated string here the UI will show in english which could be incorrect. Some design systems will enforce that all strings are injected and provide no defaults to avoid that.
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.
Yaaaassssss. it's alive! The only imperative thing I found was that white horizontal line that shows up at the bottom of CodeBlock. Lemme know if you want to get together to figure out where it's coming from.
|
||
type CodeBlockVariants = 'multi-line' | 'single-line'; | ||
|
||
export interface CodeBlockProps extends Partial<Omit<HTMLDivElement, 'children'>> { |
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.
suggestion(non-blocking): I'd like to figure out if this is the best possible way to get to the type we're looking for. Way out of scope for here, but just wanted to note that somewhere.
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.
Totally, I kinda just guessed on how to do this.
packages/paste-website/src/pages/components/code-block/index.mdx
Outdated
Show resolved
Hide resolved
packages/paste-website/src/pages/components/code-block/index.mdx
Outdated
Show resolved
Hide resolved
packages/paste-website/src/pages/components/code-block/index.mdx
Outdated
Show resolved
Hide resolved
packages/paste-website/src/pages/components/code-block/index.mdx
Outdated
Show resolved
Hide resolved
packages/paste-website/src/pages/components/code-block/index.mdx
Outdated
Show resolved
Hide resolved
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 is awesome, really good work and digestible code 💯
packages/paste-core/components/code-block/src/ExternalLinkButton.tsx
Outdated
Show resolved
Hide resolved
packages/paste-website/src/pages/components/code-block/index.mdx
Outdated
Show resolved
Hide resolved
{...safelySpreadBoxProps(props)} | ||
ref={ref} | ||
element={element} | ||
as={as} |
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.
question: passing h1/h2/h3/etc doesn't change the CodeBlockHeader visually, so why do we allow for the different options? The docs say "use the correct heading level" to ensure a11y but in what situation would one be correct over another? Do we really want people to have h1 code block headers?
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 all depends on the heading hierarchy of the page. I doubt there would ever be an H1 code block header, but I can totally believe other heading levels - it all depends on the other headers on the page. For example, if the code block is underneath an H3, then the code block heading should be an h4.
You can read more about heading levels here: https://www.w3.org/WAI/tutorials/page-structure/headings/
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.
totally non-blocking but might be helpful to add a bit of this context to the a11y section of the docs page
Co-authored-by: Shadi <TheSisb@users.noreply.github.com> Co-authored-by: gloriliale <77117846+gloriliale@users.noreply.github.com>
78a9daa
to
f14c71b
Compare
214bc65
This PR includes:
@twilio-paste/code-block
package, which includes:@twilio-paste/syntax-highlighter
library: all it does is re-exportreact-syntax-highlighter
with the languages we supportContributing to Twilio