Skip to content

Commit b5da7e7

Browse files
authored
Fix broken breadcrumbs story (#666)
1 parent 444974c commit b5da7e7

File tree

8 files changed

+83
-39
lines changed

8 files changed

+83
-39
lines changed

.eslintrc.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = {
1515

1616
settings: {
1717
react: {
18-
version: "17.0.2", // React version. "detect" automatically picks the version you have installed.
18+
version: "detect", // React version. "detect" automatically picks the version you have installed.
1919
},
2020
jest: {
2121
version: "29",
@@ -32,10 +32,6 @@ module.exports = {
3232
{
3333
files: ["src/**/*.{ts,tsx}"],
3434
rules: {
35-
"@typescript-eslint/no-unsafe-return": "warn",
36-
"@typescript-eslint/no-unsafe-argument": "warn",
37-
"@typescript-eslint/no-unsafe-assignment": "warn",
38-
"@typescript-eslint/no-unsafe-member-access": "warn",
3935
// Should be in sync with https://github.com/nordcloud/eslint-config-pat/blob/master/profile/_common.js#L463
4036
"@typescript-eslint/naming-convention": [
4137
"warn",
@@ -108,15 +104,6 @@ module.exports = {
108104
format: ["PascalCase", "UPPER_CASE"],
109105
},
110106
],
111-
"@typescript-eslint/ban-types": [
112-
"error",
113-
{
114-
types: {
115-
"{}": false,
116-
},
117-
extendDefaults: true,
118-
},
119-
],
120107
},
121108
},
122109
{

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@nordcloud/gnui",
33
"description": "Nordcloud Design System - a collection of reusable React components used in Nordcloud's SaaS products",
4-
"version": "9.0.0",
4+
"version": "9.0.1",
55
"license": "MIT",
66
"repository": {
77
"type": "git",

src/components/breadcrumbs/Breadcrumbs.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,9 @@ import * as BreadcrumbsStories from "./Breadcrumbs.stories";
2525
<Canvas>
2626
<Story of={BreadcrumbsStories.Default} />
2727
</Canvas>
28+
29+
## Custom component
30+
31+
<Canvas>
32+
<Story of={BreadcrumbsStories.CustomComponent} />
33+
</Canvas>

src/components/breadcrumbs/Breadcrumbs.stories.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Meta, StoryObj } from "@storybook/react";
2+
import { Button } from "../button";
23
import { Breadcrumbs } from "./Breadcrumbs";
34

45
const meta: Meta = {
@@ -39,3 +40,40 @@ export const Default: StoryObj = {
3940

4041
name: "default",
4142
};
43+
44+
export const CustomComponent: StoryObj = {
45+
render: () => (
46+
<Breadcrumbs
47+
renderCustom={({ to }) => (
48+
<Button as="a" linkTo={to}>
49+
test123
50+
</Button>
51+
)}
52+
list={[
53+
{
54+
label: "Home",
55+
uri: `#`,
56+
},
57+
{
58+
label: "Hosts",
59+
uri: `#`,
60+
},
61+
{
62+
label: "Disabled",
63+
uri: `#`,
64+
isDisabled: true,
65+
},
66+
{
67+
label: "Hosts 2",
68+
uri: `#`,
69+
},
70+
{
71+
label: "Host Details",
72+
uri: `#`,
73+
},
74+
]}
75+
/>
76+
),
77+
78+
name: "customComponent",
79+
};

src/components/breadcrumbs/Breadcrumbs.tsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from "react";
2-
import styled, { css } from "styled-components";
2+
import styled, { css, FlattenSimpleInterpolation } from "styled-components";
33
import theme from "../../theme";
44

55
export type BreadcrumbsList = {
@@ -10,25 +10,33 @@ export type BreadcrumbsList = {
1010

1111
export type BreadcrumbsListProps = {
1212
list: BreadcrumbsList[];
13+
/**
14+
* @deprecated Might cause problems with React 18, use `renderCustom` instead
15+
*/
1316
Component?: React.FC<
1417
React.PropsWithChildren<{ to: string; isDisabled?: boolean }>
1518
>;
19+
renderCustom?: (
20+
props: React.PropsWithChildren<{
21+
to: string;
22+
isDisabled?: boolean;
23+
css: FlattenSimpleInterpolation;
24+
}>
25+
) => React.ReactNode;
1626
};
1727

18-
export function Breadcrumbs({ list, Component }: BreadcrumbsListProps) {
28+
export function Breadcrumbs({ list, renderCustom }: BreadcrumbsListProps) {
1929
return (
2030
<StyledBreadcrumbs>
2131
<ul>
2232
{list.map((breadcrumb) => (
2333
<li key={breadcrumb.label}>
24-
{Component ? (
25-
<Component
26-
isDisabled={breadcrumb.isDisabled}
27-
css={aStyles}
28-
to={breadcrumb.uri}
29-
>
30-
{breadcrumb.label}
31-
</Component>
34+
{renderCustom ? (
35+
renderCustom({
36+
isDisabled: breadcrumb.isDisabled,
37+
css: aStyles,
38+
to: breadcrumb.uri,
39+
})
3240
) : (
3341
<StyledLink
3442
isDisabled={breadcrumb.isDisabled}

src/components/toggle/Toggle.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,7 @@ import theme from "../../theme";
55
import { SingleColors } from "../../theme/config";
66
import { setColor } from "../../utils/setcolor";
77

8-
export type ToggleProps = React.ComponentProps<"button"> & {
9-
value: boolean;
10-
labelText?: string;
11-
status?: SingleColors;
12-
size?: string;
13-
onChange: (value: boolean) => void;
14-
};
15-
16-
const StyledToggle = styled.button<Pick<ToggleProps, "size" | "status">>`
8+
const StyledToggle = styled.button<Pick<CustomProps, "size" | "status">>`
179
border: 1px solid ${theme.color.interactive.primary};
1810
border-radius: ${theme.radiusDefault};
1911
line-height: ${theme.lineHeight};
@@ -61,12 +53,23 @@ const StyledToggle = styled.button<Pick<ToggleProps, "size" | "status">>`
6153
`}
6254
`;
6355

56+
type CustomProps = {
57+
value: boolean;
58+
labelText?: string;
59+
status?: SingleColors;
60+
size?: string;
61+
onChange: (value: boolean) => void;
62+
};
63+
64+
export type ToggleProps = CustomProps &
65+
React.ComponentProps<typeof StyledToggle>;
66+
6467
export function Toggle({
6568
value,
6669
labelText = "",
6770
onChange,
6871
...props
69-
}: React.ComponentProps<typeof StyledToggle>) {
72+
}: ToggleProps) {
7073
return (
7174
<StyledToggle
7275
className={value ? "active" : ""}

src/utils/flattenChildren/flattenChildren.spec.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ type Children = (
3333
| undefined
3434
)[];
3535

36-
const getChildren = (element: React.ReactElement): React.ReactNode =>
37-
element.props.children;
36+
const getChildren = (
37+
element: React.ReactElement<{ children: React.ReactNode }>
38+
): React.ReactNode => element.props.children;
39+
3840
const getTypes = (children: Children) =>
3941
React.Children.map(children, (child) => (child as React.ReactElement).type);
4042

0 commit comments

Comments
 (0)