From 9e48aec0444fe5c378614b9ffb2efc3b847f6b7a Mon Sep 17 00:00:00 2001 From: Aram <37216945+alimpens@users.noreply.github.com> Date: Wed, 24 Jan 2024 10:58:53 +0100 Subject: [PATCH 1/2] fix: Refactor subcomponents (#1050) Co-authored-by: Vincent Smedinga --- packages/react/package.json | 1 + packages/react/rollup.config.mjs | 15 +- .../react/src/Breadcrumb/Breadcrumb.test.tsx | 19 + packages/react/src/Breadcrumb/Breadcrumb.tsx | 30 +- .../src/Breadcrumb/BreadcrumbItem.test.tsx | 41 ++ .../react/src/Breadcrumb/BreadcrumbItem.tsx | 24 + packages/react/src/Breadcrumb/index.ts | 3 +- packages/react/src/Card/Card.test.tsx | 52 +- packages/react/src/Card/Card.tsx | 40 +- .../react/src/Card/CardHeadingGroup.test.tsx | 48 ++ packages/react/src/Card/CardHeadingGroup.tsx | 24 + packages/react/src/Card/CardLink.test.tsx | 41 ++ packages/react/src/Card/CardLink.tsx | 20 + packages/react/src/Card/index.ts | 2 + packages/react/src/Footer/Footer.test.tsx | 50 +- packages/react/src/Footer/Footer.tsx | 31 +- .../react/src/Footer/FooterBottom.test.tsx | 41 ++ packages/react/src/Footer/FooterBottom.tsx | 20 + packages/react/src/Footer/FooterTop.test.tsx | 41 ++ packages/react/src/Footer/FooterTop.tsx | 21 + packages/react/src/Footer/index.ts | 3 + .../src/OrderedList/OrderedList.test.tsx | 25 +- .../react/src/OrderedList/OrderedList.tsx | 45 +- .../src/OrderedList/OrderedListItem.test.tsx | 39 ++ .../react/src/OrderedList/OrderedListItem.tsx | 20 + packages/react/src/OrderedList/index.ts | 1 + packages/react/src/PageMenu/PageMenu.test.tsx | 2 +- packages/react/src/PageMenu/PageMenu.tsx | 60 +- .../react/src/PageMenu/PageMenuLink.test.tsx | 68 +++ packages/react/src/PageMenu/PageMenuLink.tsx | 26 + packages/react/src/PageMenu/index.ts | 3 +- .../src/UnorderedList/UnorderedList.test.tsx | 25 +- .../react/src/UnorderedList/UnorderedList.tsx | 24 +- .../UnorderedList/UnorderedListItem.test.tsx | 39 ++ .../src/UnorderedList/UnorderedListItem.tsx | 20 + packages/react/src/UnorderedList/index.ts | 1 + packages/react/tsconfig.json | 1 + pnpm-lock.yaml | 569 +----------------- 38 files changed, 702 insertions(+), 833 deletions(-) create mode 100644 packages/react/src/Breadcrumb/BreadcrumbItem.test.tsx create mode 100644 packages/react/src/Breadcrumb/BreadcrumbItem.tsx create mode 100644 packages/react/src/Card/CardHeadingGroup.test.tsx create mode 100644 packages/react/src/Card/CardHeadingGroup.tsx create mode 100644 packages/react/src/Card/CardLink.test.tsx create mode 100644 packages/react/src/Card/CardLink.tsx create mode 100644 packages/react/src/Footer/FooterBottom.test.tsx create mode 100644 packages/react/src/Footer/FooterBottom.tsx create mode 100644 packages/react/src/Footer/FooterTop.test.tsx create mode 100644 packages/react/src/Footer/FooterTop.tsx create mode 100644 packages/react/src/OrderedList/OrderedListItem.test.tsx create mode 100644 packages/react/src/OrderedList/OrderedListItem.tsx create mode 100644 packages/react/src/PageMenu/PageMenuLink.test.tsx create mode 100644 packages/react/src/PageMenu/PageMenuLink.tsx create mode 100644 packages/react/src/UnorderedList/UnorderedListItem.test.tsx create mode 100644 packages/react/src/UnorderedList/UnorderedListItem.tsx diff --git a/packages/react/package.json b/packages/react/package.json index 072de123b3..274851c20d 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -63,6 +63,7 @@ "react-dom": "18.2.0", "rollup": "4.9.4", "rollup-plugin-delete": "2.0.0", + "rollup-plugin-dts": "6.1.0", "rollup-plugin-filesize": "10.0.0", "rollup-plugin-node-externals": "6.1.2", "rollup-plugin-node-polyfills": "0.2.1", diff --git a/packages/react/rollup.config.mjs b/packages/react/rollup.config.mjs index b8dd0d2570..fa3a4fdee0 100644 --- a/packages/react/rollup.config.mjs +++ b/packages/react/rollup.config.mjs @@ -7,6 +7,8 @@ import nodeExternal from 'rollup-plugin-node-externals' import nodePolyfills from 'rollup-plugin-node-polyfills' import peerDepsExternal from 'rollup-plugin-peer-deps-external' import typescript from 'rollup-plugin-typescript2' +import dts from 'rollup-plugin-dts' +import del from 'rollup-plugin-delete' const packageJson = JSON.parse(readFileSync('./package.json', 'utf8')) @@ -46,7 +48,7 @@ export default [ include: /node_modules/, }), nodePolyfills(), - typescript({ includeDependencies: false }), + typescript({ includeDependencies: false, useTsconfigDeclarationDir: true }), babel({ presets: ['@babel/preset-react'], babelHelpers: 'runtime', @@ -58,4 +60,15 @@ export default [ filesize(), ], }, + { + input: './dist/dts/index.d.ts', + output: [{ file: 'dist/index.d.ts', format: 'es' }], + plugins: [ + dts(), + del({ + targets: 'dist/dts', + hook: 'buildEnd', + }), + ], + }, ] diff --git a/packages/react/src/Breadcrumb/Breadcrumb.test.tsx b/packages/react/src/Breadcrumb/Breadcrumb.test.tsx index d5420454df..591dc45b36 100644 --- a/packages/react/src/Breadcrumb/Breadcrumb.test.tsx +++ b/packages/react/src/Breadcrumb/Breadcrumb.test.tsx @@ -4,6 +4,25 @@ import { Breadcrumb } from './Breadcrumb' import '@testing-library/jest-dom' describe('Breadcrumb', () => { + it('renders', () => { + render() + const component = screen.getByRole('navigation') + expect(component).toBeInTheDocument() + expect(component).toBeVisible() + }) + + it('renders a design system BEM class name', () => { + render() + const component = screen.getByRole('navigation') + expect(component).toHaveClass('amsterdam-breadcrumb') + }) + + it('renders an additional class name', () => { + render() + const component = screen.getByRole('navigation') + expect(component).toHaveClass('amsterdam-breadcrumb extra') + }) + it('renders Breadcrumb component with children', () => { const breadcrumbItems = [ { label: 'Item 1', href: '/item-1' }, diff --git a/packages/react/src/Breadcrumb/Breadcrumb.tsx b/packages/react/src/Breadcrumb/Breadcrumb.tsx index 814b4470bc..eb50c94944 100644 --- a/packages/react/src/Breadcrumb/Breadcrumb.tsx +++ b/packages/react/src/Breadcrumb/Breadcrumb.tsx @@ -3,8 +3,10 @@ * Copyright (c) 2023 Gemeente Amsterdam */ +import { clsx } from 'clsx' import { forwardRef } from 'react' import type { ForwardedRef, ForwardRefExoticComponent, HTMLAttributes, PropsWithChildren, RefAttributes } from 'react' +import { BreadcrumbItem } from './BreadcrumbItem' export type BreadcrumbProps = PropsWithChildren> @@ -12,31 +14,15 @@ interface BreadcrumbComponent extends ForwardRefExoticComponent) => { - return ( -