-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(LabeledValue): Introduce component
- Loading branch information
Showing
19 changed files
with
280 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
42 changes: 42 additions & 0 deletions
42
packages/components/src/components/CopyButton/CopyButton.tsx
This file contains 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,42 @@ | ||
import React, { FC } from "react"; | ||
import copy from "copy-to-clipboard"; | ||
import { Button } from "@/components/Button"; | ||
import { Icon } from "@/components/Icon"; | ||
import { faCopy } from "@fortawesome/free-regular-svg-icons/faCopy"; | ||
import locales from "./locales/*.locale.json"; | ||
import { useLocalizedStringFormatter } from "react-aria"; | ||
import { Tooltip, TooltipTrigger } from "@/components/Tooltip"; | ||
|
||
export interface CopyButtonProps { | ||
value: string; | ||
className?: string; | ||
} | ||
|
||
export const CopyButton: FC<CopyButtonProps> = (props) => { | ||
const { value, className } = props; | ||
|
||
const stringFormatter = useLocalizedStringFormatter(locales); | ||
|
||
const tooltip = stringFormatter.format("copyButton.copy"); | ||
|
||
const copyValue = () => { | ||
copy(value); | ||
}; | ||
|
||
return ( | ||
<TooltipTrigger> | ||
<Button | ||
className={className} | ||
onPress={copyValue} | ||
aria-label={tooltip} | ||
variant="plain" | ||
small | ||
> | ||
<Icon faIcon={faCopy} /> | ||
</Button> | ||
<Tooltip>{tooltip}</Tooltip> | ||
</TooltipTrigger> | ||
); | ||
}; | ||
|
||
export default CopyButton; |
This file contains 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,3 @@ | ||
import { CopyButton } from "./CopyButton"; | ||
export { type CopyButtonProps, CopyButton } from "./CopyButton"; | ||
export default CopyButton; |
3 changes: 3 additions & 0 deletions
3
packages/components/src/components/CopyButton/locales/de-DE.locale.json
This file contains 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,3 @@ | ||
{ | ||
"copyButton.copy": "Kopieren" | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/components/src/components/CopyButton/locales/en-EN.locale.json
This file contains 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,3 @@ | ||
{ | ||
"copyButton.copy": "Copy" | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/components/src/components/CopyButton/stories/Default.stories.tsx
This file contains 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,17 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import React from "react"; | ||
import { CopyButton } from "../CopyButton"; | ||
|
||
const meta: Meta<typeof CopyButton> = { | ||
title: "Buttons/CopyButton", | ||
component: CopyButton, | ||
render: (props) => <CopyButton {...props} value="Copied content" />, | ||
parameters: { | ||
controls: { exclude: ["value", "className"] }, | ||
}, | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof CopyButton>; | ||
|
||
export const Default: Story = {}; |
30 changes: 30 additions & 0 deletions
30
packages/components/src/components/LabeledValue/LabeledValue.module.scss
This file contains 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,30 @@ | ||
@import "@/styles"; | ||
|
||
.labeledValue { | ||
display: grid; | ||
grid-template-areas: | ||
"label" | ||
"value"; | ||
row-gap: var(--labeled-value--label-to-value-spacing); | ||
column-gap: var(--labeled-value--value-to-button-spacing); | ||
grid-template-columns: auto 1fr; | ||
|
||
&:has(.button) { | ||
grid-template-areas: | ||
"label label" | ||
"value button"; | ||
} | ||
} | ||
|
||
.label { | ||
grid-area: label; | ||
} | ||
|
||
.content { | ||
grid-area: value; | ||
} | ||
|
||
.button { | ||
grid-area: button; | ||
justify-self: start; | ||
} |
36 changes: 36 additions & 0 deletions
36
packages/components/src/components/LabeledValue/LabeledValue.tsx
This file contains 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 React, { FC, PropsWithChildren } from "react"; | ||
import styles from "./LabeledValue.module.scss"; | ||
import clsx from "clsx"; | ||
import { PropsContext, PropsContextProvider } from "@/lib/propsContext"; | ||
|
||
export interface LabeledValueProps extends PropsWithChildren { | ||
className?: string; | ||
} | ||
|
||
export const LabeledValue: FC<LabeledValueProps> = (props) => { | ||
const { children, className } = props; | ||
|
||
const rootClassName = clsx(styles.labeledValue, className); | ||
|
||
const propsContext: PropsContext = { | ||
Label: { | ||
className: styles.label, | ||
}, | ||
Content: { | ||
className: styles.content, | ||
}, | ||
Button: { | ||
className: styles.button, | ||
}, | ||
}; | ||
|
||
return ( | ||
<div className={rootClassName}> | ||
<PropsContextProvider props={propsContext}> | ||
{children} | ||
</PropsContextProvider> | ||
</div> | ||
); | ||
}; | ||
|
||
export default LabeledValue; |
This file contains 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,3 @@ | ||
import { LabeledValue } from "./LabeledValue"; | ||
export { type LabeledValueProps, LabeledValue } from "./LabeledValue"; | ||
export default LabeledValue; |
35 changes: 35 additions & 0 deletions
35
packages/components/src/components/LabeledValue/stories/Default.stories.tsx
This file contains 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,35 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import LabeledValue from "../LabeledValue"; | ||
import React from "react"; | ||
import { Label } from "@/components/Label"; | ||
import { Content } from "@/components/Content"; | ||
import { CopyButton } from "@/components/CopyButton"; | ||
|
||
const meta: Meta<typeof LabeledValue> = { | ||
title: "Content/Labeled Value", | ||
component: LabeledValue, | ||
parameters: { | ||
controls: { exclude: ["className"] }, | ||
}, | ||
render: (props) => ( | ||
<LabeledValue {...props}> | ||
<Label>Project</Label> | ||
<Content>My proSpace</Content> | ||
</LabeledValue> | ||
), | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof LabeledValue>; | ||
|
||
export const Default: Story = {}; | ||
|
||
export const WithCopyButton: Story = { | ||
render: (props) => ( | ||
<LabeledValue {...props}> | ||
<Label>Project</Label> | ||
<Content>My proSpace</Content> | ||
<CopyButton value="My proSpace" /> | ||
</LabeledValue> | ||
), | ||
}; |
35 changes: 35 additions & 0 deletions
35
packages/components/src/components/LabeledValue/stories/EdgeCases.stories.tsx
This file contains 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,35 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import LabeledValue from "../LabeledValue"; | ||
import defaultMeta from "./Default.stories"; | ||
import { dummyText } from "@/lib/dev/dummyText"; | ||
import { Label } from "@/components/Label"; | ||
import { Content } from "@/components/Content"; | ||
import React from "react"; | ||
import { CopyButton } from "@/components/CopyButton"; | ||
|
||
const meta: Meta<typeof LabeledValue> = { | ||
title: "Content/Labeled Value/Edge Cases", | ||
...defaultMeta, | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof LabeledValue>; | ||
|
||
export const LongLabel: Story = { | ||
render: (props) => ( | ||
<LabeledValue {...props}> | ||
<Label>{dummyText.medium}</Label> | ||
<Content>{dummyText.short}</Content> | ||
<CopyButton value={dummyText.short} /> | ||
</LabeledValue> | ||
), | ||
}; | ||
export const LongContent: Story = { | ||
render: (props) => ( | ||
<LabeledValue {...props}> | ||
<Label>{dummyText.medium}</Label> | ||
<Content>{dummyText.long}</Content> | ||
<CopyButton value={dummyText.long} /> | ||
</LabeledValue> | ||
), | ||
}; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
4f1cb09
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.
Coverage report for
./packages/components/
Test suite run success
51 tests passing in 9 suites.
Report generated by 🧪jest coverage report action from 4f1cb09