-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
feat(ui-components): add Signature and FunctionSignature components #8667
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
Open
canerakdas
wants to merge
9
commits into
nodejs:main
Choose a base branch
from
canerakdas:feat/functionsignature
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+568
−1
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d2cc30b
feat(ui-components): add Signature and FunctionSignature components
canerakdas a34cc13
fix: title overflow and mobile return icon alignment
canerakdas 086b05c
chore: patch version
canerakdas 607f618
fix: static heading tag can cause semantic problems
canerakdas 82ac683
chore: unnecessary fragment removed
canerakdas 8ba0056
fix: wrong naming on signature stories
canerakdas 4b9890e
chore: unused classnames removed
canerakdas c1af239
chore: try to make Vercel happy
canerakdas 988a489
Update index.stories.tsx
canerakdas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
packages/ui-components/src/Common/Signature/SignatureHeader/index.module.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| @reference "../../../styles/index.css"; | ||
|
|
||
| .header { | ||
| @apply flex | ||
| items-start | ||
| gap-1; | ||
| } | ||
|
|
||
| .attribute { | ||
| @apply font-ibm-plex-mono | ||
| inline-flex | ||
| flex-wrap | ||
| items-center | ||
| gap-1 | ||
| text-sm | ||
| font-semibold; | ||
|
|
||
| .longName { | ||
| @apply break-all | ||
| sm:break-keep; | ||
| } | ||
|
|
||
| &.return { | ||
| @apply font-open-sans | ||
| shrink-0; | ||
|
|
||
| svg { | ||
| @apply size-4; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| .type { | ||
| @apply font-ibm-plex-mono | ||
| inline-flex | ||
| flex-wrap | ||
| gap-0.5 | ||
| text-sm | ||
| break-all; | ||
|
|
||
| a { | ||
| @apply text-green-700 | ||
| dark:text-green-400; | ||
| } | ||
| } |
51 changes: 51 additions & 0 deletions
51
packages/ui-components/src/Common/Signature/SignatureHeader/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { ArrowTurnDownLeftIcon } from '@heroicons/react/24/outline'; | ||
| import classNames from 'classnames'; | ||
|
|
||
| import type Signature from '#ui/Common/Signature'; | ||
| import type { ComponentProps, FC } from 'react'; | ||
|
|
||
| import styles from './index.module.css'; | ||
|
|
||
| type SignatureHeaderProps = { isReturn?: boolean } & Omit< | ||
| ComponentProps<typeof Signature>, | ||
| 'title' | 'description' | ||
| >; | ||
|
|
||
| const SignatureHeader: FC<SignatureHeaderProps> = ({ | ||
| name, | ||
| type, | ||
| optional, | ||
| isReturn = false, | ||
| }) => ( | ||
| <div className={styles.header}> | ||
| {name && ( | ||
| <span | ||
| className={classNames(styles.attribute, { | ||
| [styles.return]: isReturn, | ||
| })} | ||
| > | ||
| {isReturn && <ArrowTurnDownLeftIcon />} | ||
| <span | ||
| className={classNames({ | ||
| [styles.longName]: name.length > 16, | ||
| })} | ||
| > | ||
| {name}: | ||
| {optional && ( | ||
| <span | ||
| role="img" | ||
| aria-label="Optional" | ||
| data-tooltip="Optional" | ||
| tabIndex={0} | ||
| > | ||
| ? | ||
| </span> | ||
| )} | ||
| </span> | ||
| </span> | ||
| )} | ||
| {type && <span className={styles.type}>{type}</span>} | ||
| </div> | ||
| ); | ||
|
|
||
| export default SignatureHeader; | ||
50 changes: 50 additions & 0 deletions
50
packages/ui-components/src/Common/Signature/SignatureItem/index.module.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| @reference "../../../styles/index.css"; | ||
|
|
||
| .item { | ||
| @apply flex | ||
| flex-col | ||
| gap-1; | ||
| } | ||
|
|
||
| .return { | ||
| @apply rounded-sm | ||
| bg-green-100 | ||
| px-4 | ||
| py-3 | ||
| dark:bg-neutral-900/40; | ||
| } | ||
|
|
||
| .children { | ||
| @apply relative | ||
| flex | ||
| flex-col | ||
| rounded-sm | ||
| border | ||
| border-neutral-200 | ||
| dark:border-neutral-900; | ||
|
|
||
| &:has(> .return:only-child) { | ||
| @apply border-0; | ||
| } | ||
|
|
||
| &:not(:has(.return:only-child)) .return { | ||
| @apply mx-4 | ||
| mb-3; | ||
| } | ||
|
|
||
| .item:not(.return) { | ||
| @apply mx-4 | ||
| py-3; | ||
| } | ||
|
|
||
| .item:not(:last-child, :has(+ .return)) { | ||
| @apply border-b | ||
| border-neutral-200 | ||
| dark:border-neutral-900; | ||
| } | ||
| } | ||
|
|
||
| .description { | ||
| @apply text-sm | ||
| break-all; | ||
| } |
36 changes: 36 additions & 0 deletions
36
packages/ui-components/src/Common/Signature/SignatureItem/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import classNames from 'classnames'; | ||
|
|
||
| import SignatureHeader from '#ui/Common/Signature/SignatureHeader'; | ||
|
|
||
| import type Signature from '#ui/Common/Signature'; | ||
| import type { ComponentProps, FC, PropsWithChildren } from 'react'; | ||
|
|
||
| import styles from './index.module.css'; | ||
|
|
||
| type SignatureItemProps = Omit<ComponentProps<typeof Signature>, 'title'>; | ||
|
|
||
| const SignatureItem: FC<PropsWithChildren<SignatureItemProps>> = ({ | ||
| kind = 'default', | ||
| name, | ||
| type, | ||
| description, | ||
| optional, | ||
| children, | ||
| }) => ( | ||
| <div | ||
| className={classNames(styles.item, { | ||
| [styles.return]: kind === 'return', | ||
| })} | ||
| > | ||
| <SignatureHeader | ||
| name={name} | ||
| type={type} | ||
| optional={optional} | ||
| isReturn={kind === 'return'} | ||
| /> | ||
| {description && <div className={styles.description}>{description}</div>} | ||
| {children && <div className={styles.children}>{children}</div>} | ||
| </div> | ||
| ); | ||
|
|
||
| export default SignatureItem; |
24 changes: 24 additions & 0 deletions
24
packages/ui-components/src/Common/Signature/SignatureRoot/index.module.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| @reference "../../../styles/index.css"; | ||
|
|
||
| .container { | ||
| @apply flex | ||
| flex-col | ||
| gap-3; | ||
| } | ||
|
|
||
| .title { | ||
| @apply text-base | ||
| font-semibold; | ||
| } | ||
|
|
||
| .root { | ||
| @apply flex | ||
| flex-col | ||
| gap-4 | ||
| rounded-sm | ||
| border | ||
| border-neutral-200 | ||
| px-4 | ||
| py-3 | ||
| dark:border-neutral-900; | ||
| } |
26 changes: 26 additions & 0 deletions
26
packages/ui-components/src/Common/Signature/SignatureRoot/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { useId } from 'react'; | ||
|
|
||
| import type Signature from '#ui/Common/Signature'; | ||
| import type { ComponentProps, FC, PropsWithChildren } from 'react'; | ||
|
|
||
| import styles from './index.module.css'; | ||
|
|
||
| type SignatureRootProps = Pick<ComponentProps<typeof Signature>, 'title'>; | ||
|
|
||
| const SignatureRoot: FC<PropsWithChildren<SignatureRootProps>> = ({ | ||
| title, | ||
| children, | ||
| }) => { | ||
| const titleId = useId(); | ||
|
|
||
| return ( | ||
| <section className={styles.container} aria-labelledby={titleId}> | ||
| <div className={styles.title} id={titleId}> | ||
| {title} | ||
| </div> | ||
| <div className={styles.root}>{children}</div> | ||
| </section> | ||
| ); | ||
| }; | ||
|
|
||
| export default SignatureRoot; |
100 changes: 100 additions & 0 deletions
100
packages/ui-components/src/Common/Signature/index.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| import Signature from '#ui/Common/Signature'; | ||
|
|
||
| import type { Meta as MetaObj, StoryObj } from '@storybook/react-webpack5'; | ||
|
|
||
| type Story = StoryObj<typeof Signature>; | ||
| type Meta = MetaObj<typeof Signature>; | ||
|
|
||
| export const Default: Story = { | ||
| args: { | ||
| title: 'Attributes', | ||
| children: ( | ||
| <> | ||
| <Signature | ||
| name="attribute1" | ||
| type={ | ||
| <> | ||
| <a href="#"><Type1></a>|<a href="#"><Type2></a> | ||
| </> | ||
| } | ||
| /> | ||
| <Signature | ||
| name="attribute2" | ||
| optional | ||
| type={<a href="#"><Object></a>} | ||
| description="An optional attribute." | ||
| > | ||
| <Signature name="option1" type={<a href="#"><Type1></a>} /> | ||
| <Signature name="option2" type={<a href="#"><Type2></a>} /> | ||
| <Signature | ||
| name="option3" | ||
| type={<a href="#"><Type3></a>} | ||
| description="One of the available options." | ||
| /> | ||
| </Signature> | ||
| <Signature | ||
| name="Returns" | ||
| type={<a href="#"><Type4></a>} | ||
| description="Returns the result of the function." | ||
| kind="return" | ||
| /> | ||
| </> | ||
| ), | ||
| }, | ||
| }; | ||
|
|
||
| export const WithLongAttributeNames: Story = { | ||
| args: { | ||
| title: 'Attributes', | ||
| children: ( | ||
| <> | ||
| <Signature | ||
| name="thisIsAnAttributeWithAnExcessivelyLongNameToTestTextWrapping" | ||
| type={ | ||
| <> | ||
| <a href="#"><Type1></a>|<a href="#"><Type3></a> | ||
| </> | ||
| } | ||
| /> | ||
| </> | ||
| ), | ||
| }, | ||
| }; | ||
|
|
||
| export const WithLongTypeAndAttributeNames: Story = { | ||
| args: { | ||
| title: 'Attributes', | ||
| children: ( | ||
| <> | ||
| <Signature | ||
| name="attribute1" | ||
| type={ | ||
| <> | ||
| <a href="#"> | ||
| <ThisIsATypeWithAnExcessivelyLongNameToTestTextWrapping> | ||
| </a> | ||
| </> | ||
| } | ||
| /> | ||
| </> | ||
| ), | ||
| }, | ||
| }; | ||
|
|
||
| export const OptionalAttribute: Story = { | ||
| args: { | ||
| title: 'Attributes', | ||
| children: ( | ||
| <Signature | ||
| name="optionalAttribute" | ||
| optional | ||
| type={<a href="#"><Object></a>} | ||
| description="An optional attribute." | ||
| /> | ||
| ), | ||
| }, | ||
| }; | ||
|
|
||
| export default { | ||
| component: Signature, | ||
| } as Meta; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import SignatureItem from '#ui/Common/Signature/SignatureItem'; | ||
| import SignatureRoot from '#ui/Common/Signature/SignatureRoot'; | ||
|
|
||
| import type { FC, PropsWithChildren, ReactNode } from 'react'; | ||
|
|
||
| export type SignatureProps = { | ||
| title?: string; | ||
| kind?: 'default' | 'return'; | ||
| name?: string; | ||
| type?: ReactNode; | ||
| description?: ReactNode; | ||
| optional?: boolean; | ||
| }; | ||
canerakdas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const Signature: FC<PropsWithChildren<SignatureProps>> = ({ | ||
| kind = 'default', | ||
| name, | ||
| type, | ||
| description, | ||
| optional, | ||
| title, | ||
| children, | ||
| }) => { | ||
| if (title) { | ||
| return <SignatureRoot title={title}>{children}</SignatureRoot>; | ||
| } | ||
|
|
||
| return ( | ||
| <SignatureItem | ||
| kind={kind} | ||
| name={name} | ||
| type={type} | ||
| description={description} | ||
| optional={optional} | ||
| > | ||
| {children} | ||
| </SignatureItem> | ||
| ); | ||
| }; | ||
|
|
||
| export default Signature; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.