Skip to content

Commit

Permalink
Fix broken breadcrumbs story (#666)
Browse files Browse the repository at this point in the history
  • Loading branch information
nowyDEV authored Oct 3, 2023
1 parent 444974c commit b5da7e7
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 39 deletions.
15 changes: 1 addition & 14 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {

settings: {
react: {
version: "17.0.2", // React version. "detect" automatically picks the version you have installed.
version: "detect", // React version. "detect" automatically picks the version you have installed.
},
jest: {
version: "29",
Expand All @@ -32,10 +32,6 @@ module.exports = {
{
files: ["src/**/*.{ts,tsx}"],
rules: {
"@typescript-eslint/no-unsafe-return": "warn",
"@typescript-eslint/no-unsafe-argument": "warn",
"@typescript-eslint/no-unsafe-assignment": "warn",
"@typescript-eslint/no-unsafe-member-access": "warn",
// Should be in sync with https://github.com/nordcloud/eslint-config-pat/blob/master/profile/_common.js#L463
"@typescript-eslint/naming-convention": [
"warn",
Expand Down Expand Up @@ -108,15 +104,6 @@ module.exports = {
format: ["PascalCase", "UPPER_CASE"],
},
],
"@typescript-eslint/ban-types": [
"error",
{
types: {
"{}": false,
},
extendDefaults: true,
},
],
},
},
{
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@nordcloud/gnui",
"description": "Nordcloud Design System - a collection of reusable React components used in Nordcloud's SaaS products",
"version": "9.0.0",
"version": "9.0.1",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
6 changes: 6 additions & 0 deletions src/components/breadcrumbs/Breadcrumbs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ import * as BreadcrumbsStories from "./Breadcrumbs.stories";
<Canvas>
<Story of={BreadcrumbsStories.Default} />
</Canvas>

## Custom component

<Canvas>
<Story of={BreadcrumbsStories.CustomComponent} />
</Canvas>
38 changes: 38 additions & 0 deletions src/components/breadcrumbs/Breadcrumbs.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Meta, StoryObj } from "@storybook/react";
import { Button } from "../button";
import { Breadcrumbs } from "./Breadcrumbs";

const meta: Meta = {
Expand Down Expand Up @@ -39,3 +40,40 @@ export const Default: StoryObj = {

name: "default",
};

export const CustomComponent: StoryObj = {
render: () => (
<Breadcrumbs
renderCustom={({ to }) => (
<Button as="a" linkTo={to}>
test123
</Button>
)}
list={[
{
label: "Home",
uri: `#`,
},
{
label: "Hosts",
uri: `#`,
},
{
label: "Disabled",
uri: `#`,
isDisabled: true,
},
{
label: "Hosts 2",
uri: `#`,
},
{
label: "Host Details",
uri: `#`,
},
]}
/>
),

name: "customComponent",
};
28 changes: 18 additions & 10 deletions src/components/breadcrumbs/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from "react";
import styled, { css } from "styled-components";
import styled, { css, FlattenSimpleInterpolation } from "styled-components";
import theme from "../../theme";

export type BreadcrumbsList = {
Expand All @@ -10,25 +10,33 @@ export type BreadcrumbsList = {

export type BreadcrumbsListProps = {
list: BreadcrumbsList[];
/**
* @deprecated Might cause problems with React 18, use `renderCustom` instead
*/
Component?: React.FC<
React.PropsWithChildren<{ to: string; isDisabled?: boolean }>
>;
renderCustom?: (
props: React.PropsWithChildren<{
to: string;
isDisabled?: boolean;
css: FlattenSimpleInterpolation;
}>
) => React.ReactNode;
};

export function Breadcrumbs({ list, Component }: BreadcrumbsListProps) {
export function Breadcrumbs({ list, renderCustom }: BreadcrumbsListProps) {
return (
<StyledBreadcrumbs>
<ul>
{list.map((breadcrumb) => (
<li key={breadcrumb.label}>
{Component ? (
<Component
isDisabled={breadcrumb.isDisabled}
css={aStyles}
to={breadcrumb.uri}
>
{breadcrumb.label}
</Component>
{renderCustom ? (
renderCustom({
isDisabled: breadcrumb.isDisabled,
css: aStyles,
to: breadcrumb.uri,
})
) : (
<StyledLink
isDisabled={breadcrumb.isDisabled}
Expand Down
23 changes: 13 additions & 10 deletions src/components/toggle/Toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,7 @@ import theme from "../../theme";
import { SingleColors } from "../../theme/config";
import { setColor } from "../../utils/setcolor";

export type ToggleProps = React.ComponentProps<"button"> & {
value: boolean;
labelText?: string;
status?: SingleColors;
size?: string;
onChange: (value: boolean) => void;
};

const StyledToggle = styled.button<Pick<ToggleProps, "size" | "status">>`
const StyledToggle = styled.button<Pick<CustomProps, "size" | "status">>`
border: 1px solid ${theme.color.interactive.primary};
border-radius: ${theme.radiusDefault};
line-height: ${theme.lineHeight};
Expand Down Expand Up @@ -61,12 +53,23 @@ const StyledToggle = styled.button<Pick<ToggleProps, "size" | "status">>`
`}
`;

type CustomProps = {
value: boolean;
labelText?: string;
status?: SingleColors;
size?: string;
onChange: (value: boolean) => void;
};

export type ToggleProps = CustomProps &
React.ComponentProps<typeof StyledToggle>;

export function Toggle({
value,
labelText = "",
onChange,
...props
}: React.ComponentProps<typeof StyledToggle>) {
}: ToggleProps) {
return (
<StyledToggle
className={value ? "active" : ""}
Expand Down
6 changes: 4 additions & 2 deletions src/utils/flattenChildren/flattenChildren.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ type Children = (
| undefined
)[];

const getChildren = (element: React.ReactElement): React.ReactNode =>
element.props.children;
const getChildren = (
element: React.ReactElement<{ children: React.ReactNode }>
): React.ReactNode => element.props.children;

const getTypes = (children: Children) =>
React.Children.map(children, (child) => (child as React.ReactElement).type);

Expand Down

0 comments on commit b5da7e7

Please sign in to comment.