From 9c3b9dd7eeda9813e8913818367a4f42d67698e5 Mon Sep 17 00:00:00 2001 From: Ramon Mulia Date: Wed, 20 Nov 2024 12:15:27 -0300 Subject: [PATCH 01/15] adding breadcrumbs component --- .../3-components/2-library/4-breadcrumbs.mdx | 33 ++++++++++++++ examples/nextjs/src/app/page.tsx | 17 +++++++ packages/design/tailwind/css/components.css | 34 ++++++++++++++ .../html/ds/src/breadcrumbs/breadcrumbs.html | 17 +++++++ .../ds/src/breadcrumbs/breadcrumbs.stories.ts | 25 +++++++++++ .../src/breadcrumbs/breadcrumbs.stories.tsx | 40 +++++++++++++++++ .../ds/src/breadcrumbs/breadcrumbs.test.tsx | 44 +++++++++++++++++++ .../react/ds/src/breadcrumbs/breadcrumbs.tsx | 31 +++++++++++++ packages/react/ds/src/index.ts | 1 + 9 files changed, 242 insertions(+) create mode 100644 packages/html/ds/src/breadcrumbs/breadcrumbs.html create mode 100644 packages/html/ds/src/breadcrumbs/breadcrumbs.stories.ts create mode 100644 packages/react/ds/src/breadcrumbs/breadcrumbs.stories.tsx create mode 100644 packages/react/ds/src/breadcrumbs/breadcrumbs.test.tsx create mode 100644 packages/react/ds/src/breadcrumbs/breadcrumbs.tsx diff --git a/apps/docs/content/3-components/2-library/4-breadcrumbs.mdx b/apps/docs/content/3-components/2-library/4-breadcrumbs.mdx index 377bcfef1..a0bdcd136 100644 --- a/apps/docs/content/3-components/2-library/4-breadcrumbs.mdx +++ b/apps/docs/content/3-components/2-library/4-breadcrumbs.mdx @@ -9,6 +9,39 @@ status: in-development + + + HTML + React + + + ```html + + ``` + + + ```react + import { Breadcrumbs } from '@govie-ds/react'; + + + + ``` + + + ## When to use this component ## When not to use this component + diff --git a/examples/nextjs/src/app/page.tsx b/examples/nextjs/src/app/page.tsx index 05514e452..22a152e52 100644 --- a/examples/nextjs/src/app/page.tsx +++ b/examples/nextjs/src/app/page.tsx @@ -20,6 +20,7 @@ import { Combobox, Chip, Alert, + Breadcrumbs, } from "@govie-ds/react"; export default function Home() { @@ -52,6 +53,22 @@ export default function Home() {
+ Heading This is a pre-release version ol { + @apply gi-inline-flex gi-list-none gi-gap-5; +} + +.gi-breadcrumbs > ol > :not([hidden]) ~ :not([hidden]) { + @apply gi-mx-0; +} + +.gi-breadcrumbs > ol > li { + @apply gi-relative; +} + +.gi-breadcrumbs > ol > li:not(:first-child)::before { + @apply gi-block + gi-absolute + gi-top-1 + gi-bottom-0 + gi-left-[-15px] + gi-w-[6px] + gi-h-[6px] + gi-m-auto + gi-border-t-[1px] + gi-border-r-[1px] + gi-border-gray-500 + gi-rotate-45; + content: ''; +} +/* End of Breadcrumbs */ diff --git a/packages/html/ds/src/breadcrumbs/breadcrumbs.html b/packages/html/ds/src/breadcrumbs/breadcrumbs.html new file mode 100644 index 000000000..bd80b571a --- /dev/null +++ b/packages/html/ds/src/breadcrumbs/breadcrumbs.html @@ -0,0 +1,17 @@ + diff --git a/packages/html/ds/src/breadcrumbs/breadcrumbs.stories.ts b/packages/html/ds/src/breadcrumbs/breadcrumbs.stories.ts new file mode 100644 index 000000000..22223aa0d --- /dev/null +++ b/packages/html/ds/src/breadcrumbs/breadcrumbs.stories.ts @@ -0,0 +1,25 @@ +import type { Meta, StoryObj } from '@storybook/react'; +import html from './breadcrumbs.html?raw'; + +const meta = { + title: 'Navigation/Breadcrumbs', + parameters: { + docs: { + description: { + component: + 'The breadcrumbs component helps users to understand where they are within a website’s structure and move between levels.', + }, + }, + }, +} satisfies Meta; + +export default meta; +type Story = StoryObj; + +export const Default: Story = { + //@ts-expect-error Render function returns raw HTML string, not a React component + render: (_, { parameters }) => { + parameters.renderedHtml = html; + return html; + }, +}; diff --git a/packages/react/ds/src/breadcrumbs/breadcrumbs.stories.tsx b/packages/react/ds/src/breadcrumbs/breadcrumbs.stories.tsx new file mode 100644 index 000000000..854be2f8b --- /dev/null +++ b/packages/react/ds/src/breadcrumbs/breadcrumbs.stories.tsx @@ -0,0 +1,40 @@ +import type { Meta, StoryObj } from '@storybook/react'; +import { Breadcrumbs } from './breadcrumbs.js'; + +const meta = { + title: 'Navigation/Breadcrumbs', + parameters: { + docs: { + description: { + component: + 'The breadcrumbs component helps users to understand where they are within a website’s structure and move between levels.', + }, + }, + }, + component: Breadcrumbs, +} satisfies Meta; + +export default meta; +type Story = StoryObj; + +export const Default: Story = { + argTypes: { + links: { + control: 'object', + description: + 'Array of breadcrumb links, each with `href` and `label` properties.', + table: { + type: { + summary: 'Array<{ href: string; label: string }>', + }, + }, + }, + }, + args: { + links: [ + { href: '/', label: 'Home' }, + { href: '#', label: 'Passports' }, + { href: '#', label: 'Travel abroad' }, + ], + }, +}; diff --git a/packages/react/ds/src/breadcrumbs/breadcrumbs.test.tsx b/packages/react/ds/src/breadcrumbs/breadcrumbs.test.tsx new file mode 100644 index 000000000..779437015 --- /dev/null +++ b/packages/react/ds/src/breadcrumbs/breadcrumbs.test.tsx @@ -0,0 +1,44 @@ +import { render, cleanup } from '../test-utils.js'; +import { Breadcrumbs } from './breadcrumbs.js'; + +describe('govieBreadcrumbs', () => { + afterEach(cleanup); + it('should render a breadcrumb with the correct content', () => { + const { getByTestId } = render( + , + ); + expect(getByTestId('govie-breadcrumbs')).toBeInTheDocument(); + expect(getByTestId('breadcrumb_item_0')).toBeInTheDocument(); + expect(getByTestId('breadcrumb_item_1')).toBeInTheDocument(); + }); + + it('should pass axe accessibility tests', async () => { + const { axe } = render( + , + ); + + await axe(); + }); +}); diff --git a/packages/react/ds/src/breadcrumbs/breadcrumbs.tsx b/packages/react/ds/src/breadcrumbs/breadcrumbs.tsx new file mode 100644 index 000000000..744c7c348 --- /dev/null +++ b/packages/react/ds/src/breadcrumbs/breadcrumbs.tsx @@ -0,0 +1,31 @@ +import React from 'react'; +import { Link } from '../link/link.js'; + +export type BreadcrumbProps = { + links: { label: string; href: string }[]; +}; + +export const Breadcrumbs = ({ links = [] }: BreadcrumbProps) => { + return ( + + ); +}; diff --git a/packages/react/ds/src/index.ts b/packages/react/ds/src/index.ts index 3ae834718..63f3db325 100644 --- a/packages/react/ds/src/index.ts +++ b/packages/react/ds/src/index.ts @@ -44,3 +44,4 @@ export * from './checkbox/checkboxes-group.js'; export * from './spinner/spinner.js'; export { Alert } from './alert/alert.js'; export * from './pagination/pagination.js'; +export * from './breadcrumbs/breadcrumbs.js'; From 96d2dce07f5989842827fae3aa873bcefb045c10 Mon Sep 17 00:00:00 2001 From: Ramon Mulia Date: Thu, 21 Nov 2024 10:33:25 -0300 Subject: [PATCH 02/15] adding docs --- apps/docs/content/3-components/2-library/4-breadcrumbs.mdx | 6 +++++- apps/docs/src/components/document/common/mdx.tsx | 2 ++ apps/docs/src/lib/components.ts | 6 ++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/apps/docs/content/3-components/2-library/4-breadcrumbs.mdx b/apps/docs/content/3-components/2-library/4-breadcrumbs.mdx index a0bdcd136..79119e4a9 100644 --- a/apps/docs/content/3-components/2-library/4-breadcrumbs.mdx +++ b/apps/docs/content/3-components/2-library/4-breadcrumbs.mdx @@ -9,6 +9,8 @@ status: in-development + + HTML @@ -35,13 +37,15 @@ status: in-development ```react import { Breadcrumbs } from '@govie-ds/react'; - + ``` ## When to use this component +Use breadcrumbs to help users understand their location within a website or application hierarchy and navigate back to higher levels easily. ## When not to use this component +Avoid breadcrumbs on websites or applications with a flat structure, where there is no clear hierarchy or depth (e.g., single-page applications or sites with only top-level pages) diff --git a/apps/docs/src/components/document/common/mdx.tsx b/apps/docs/src/components/document/common/mdx.tsx index ee8555aa5..c58a3c533 100644 --- a/apps/docs/src/components/document/common/mdx.tsx +++ b/apps/docs/src/components/document/common/mdx.tsx @@ -27,6 +27,7 @@ import { CheckboxesGroup, Spinner, Pagination, + Breadcrumbs, } from '@govie-ds/react'; import { MDXComponents } from 'mdx/types'; import { useMDXComponent } from 'next-contentlayer/hooks'; @@ -190,6 +191,7 @@ const documentComponents: MDXComponents = { ), Pagination: (props) => , + Breadcrumbs: (props) => , }; export function Mdx({ code }: MdxProps) { diff --git a/apps/docs/src/lib/components.ts b/apps/docs/src/lib/components.ts index e88df1810..04a2b78a9 100644 --- a/apps/docs/src/lib/components.ts +++ b/apps/docs/src/lib/components.ts @@ -837,14 +837,16 @@ export function getComponents(): ComponentDetail[] { { platform: { id: 'global', + href: '?path=/docs/navigation-breadcrumbs--docs', }, - status: 'considering', + status: 'beta', }, { platform: { id: 'react', + href: '?path=/docs/navigation-breadcrumbs--docs', }, - status: 'considering', + status: 'beta', }, ], }, From e846210d2aef7231f52a2d54639598955a48392f Mon Sep 17 00:00:00 2001 From: Ramon Mulia Date: Thu, 21 Nov 2024 12:13:52 -0300 Subject: [PATCH 03/15] adding aria props --- packages/html/ds/src/breadcrumbs/breadcrumbs.html | 2 +- packages/react/ds/src/breadcrumbs/breadcrumbs.tsx | 7 ++++++- packages/react/ds/src/link/link.tsx | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/html/ds/src/breadcrumbs/breadcrumbs.html b/packages/html/ds/src/breadcrumbs/breadcrumbs.html index bd80b571a..deb7a91bb 100644 --- a/packages/html/ds/src/breadcrumbs/breadcrumbs.html +++ b/packages/html/ds/src/breadcrumbs/breadcrumbs.html @@ -11,7 +11,7 @@ Passports
  • - Travel abroad + Travel abroad
  • diff --git a/packages/react/ds/src/breadcrumbs/breadcrumbs.tsx b/packages/react/ds/src/breadcrumbs/breadcrumbs.tsx index 744c7c348..9345d1a64 100644 --- a/packages/react/ds/src/breadcrumbs/breadcrumbs.tsx +++ b/packages/react/ds/src/breadcrumbs/breadcrumbs.tsx @@ -20,7 +20,12 @@ export const Breadcrumbs = ({ links = [] }: BreadcrumbProps) => { key={`breadcrumb_item_${index}`} data-testid={`breadcrumb_item_${index}`} > - + {label} diff --git a/packages/react/ds/src/link/link.tsx b/packages/react/ds/src/link/link.tsx index 068c8e5cc..d27077560 100644 --- a/packages/react/ds/src/link/link.tsx +++ b/packages/react/ds/src/link/link.tsx @@ -7,7 +7,7 @@ export type LinkProps = { noColor?: boolean; external?: boolean; size?: 'sm' | 'md'; -}; +} & React.AriaAttributes; export function Link({ as: Component = 'a', @@ -18,6 +18,7 @@ export function Link({ noVisited = false, noColor = false, external = false, + ...ariaProps }: LinkProps) { return ( {children} From d93a98c4385d641447fd9607627e2552ee4ab463 Mon Sep 17 00:00:00 2001 From: Ramon Mulia Date: Thu, 21 Nov 2024 12:49:08 -0300 Subject: [PATCH 04/15] fix lint --- packages/html/ds/src/breadcrumbs/breadcrumbs.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/html/ds/src/breadcrumbs/breadcrumbs.html b/packages/html/ds/src/breadcrumbs/breadcrumbs.html index deb7a91bb..3abcd87aa 100644 --- a/packages/html/ds/src/breadcrumbs/breadcrumbs.html +++ b/packages/html/ds/src/breadcrumbs/breadcrumbs.html @@ -11,7 +11,9 @@ Passports
  • - Travel abroad + Travel abroad
  • From b5f30bed10667675b31a8d5fed273278a683b3ff Mon Sep 17 00:00:00 2001 From: Ramon Mulia Date: Fri, 22 Nov 2024 10:04:18 -0300 Subject: [PATCH 05/15] updating styles --- .../3-components/2-library/4-breadcrumbs.mdx | 50 +++++++++---- .../src/components/document/common/mdx.tsx | 6 ++ examples/nextjs/src/app/page.tsx | 27 +++---- packages/design/tailwind/css/components.css | 28 ++++--- packages/design/tailwind/css/typography.css | 19 +++-- .../html/ds/src/breadcrumbs/breadcrumbs.html | 29 ++++--- .../src/breadcrumbs/breadcrumbs.stories.tsx | 33 ++++---- .../ds/src/breadcrumbs/breadcrumbs.test.tsx | 75 +++++++++++-------- .../react/ds/src/breadcrumbs/breadcrumbs.tsx | 57 +++++++------- packages/react/ds/src/breadcrumbs/types.ts | 17 +++++ 10 files changed, 210 insertions(+), 131 deletions(-) create mode 100644 packages/react/ds/src/breadcrumbs/types.ts diff --git a/apps/docs/content/3-components/2-library/4-breadcrumbs.mdx b/apps/docs/content/3-components/2-library/4-breadcrumbs.mdx index 79119e4a9..abaf27022 100644 --- a/apps/docs/content/3-components/2-library/4-breadcrumbs.mdx +++ b/apps/docs/content/3-components/2-library/4-breadcrumbs.mdx @@ -9,7 +9,12 @@ status: in-development - + + Home + + Documentation + Travel abroad + @@ -18,30 +23,42 @@ status: in-development ```html - ``` ```react - import { Breadcrumbs } from '@govie-ds/react'; + import { Breadcrumbs, BreadcrumbLink, BreadcrumbEllipses, BreadcrumbCurrentLink } from '@govie-ds/react'; - + + Home + + Documentation + Travel abroad + - ``` - - +``` + + ## When to use this component Use breadcrumbs to help users understand their location within a website or application hierarchy and navigate back to higher levels easily. @@ -49,3 +66,4 @@ Use breadcrumbs to help users understand their location within a website or appl ## When not to use this component Avoid breadcrumbs on websites or applications with a flat structure, where there is no clear hierarchy or depth (e.g., single-page applications or sites with only top-level pages) +``` diff --git a/apps/docs/src/components/document/common/mdx.tsx b/apps/docs/src/components/document/common/mdx.tsx index 4bf7a054b..9afae6562 100644 --- a/apps/docs/src/components/document/common/mdx.tsx +++ b/apps/docs/src/components/document/common/mdx.tsx @@ -29,6 +29,9 @@ import { Stack, Pagination, Breadcrumbs, + BreadcrumbCurrentLink, + BreadcrumbEllipses, + BreadcrumbLink, Alert, } from '@govie-ds/react'; import { MDXComponents } from 'mdx/types'; @@ -195,6 +198,9 @@ const documentComponents: MDXComponents = { Stack: (props) => , Pagination: (props) => , Breadcrumbs: (props) => , + BreadcrumbCurrentLink: (props) => , + BreadcrumbEllipses: (props) => , + BreadcrumbLink: (props) => , Alert: (props) => , }; diff --git a/examples/nextjs/src/app/page.tsx b/examples/nextjs/src/app/page.tsx index 0c39e5130..ec8fc15cd 100644 --- a/examples/nextjs/src/app/page.tsx +++ b/examples/nextjs/src/app/page.tsx @@ -23,6 +23,9 @@ import { Alert, Breadcrumbs, Toast, + BreadcrumbCurrentLink, + BreadcrumbEllipses, + BreadcrumbLink, } from '@govie-ds/react'; export default function Home() { @@ -61,22 +64,14 @@ export default function Home() { trigger={} />
    - + + Home + + + Documentation + + Travel + Heading This is a pre-release version ol { - @apply gi-inline-flex gi-list-none gi-gap-5; + @apply gi-inline-flex gi-list-none gi-gap-7; } .gi-breadcrumbs > ol > :not([hidden]) ~ :not([hidden]) { @@ -940,16 +939,21 @@ input[type='file' i] { .gi-breadcrumbs > ol > li:not(:first-child)::before { @apply gi-block gi-absolute - gi-top-1 gi-bottom-0 - gi-left-[-15px] - gi-w-[6px] - gi-h-[6px] - gi-m-auto - gi-border-t-[1px] - gi-border-r-[1px] - gi-border-gray-500 - gi-rotate-45; - content: ''; + gi-left-[-17px] + gi-text-gray-500 + gi-font-bold + gi-text-sm; + content: '/'; } + +.gi-breadcrumb-ellipses { + @apply gi-flex gi-h-full gi-w-full gi-items-center; +} + +.gi-breadcrumb-ellipses > div { + @apply gi-bg-gray-500 gi-w-2 gi-h-2; + clip-path: ellipse(2px 2px at center); +} + /* End of Breadcrumbs */ diff --git a/packages/design/tailwind/css/typography.css b/packages/design/tailwind/css/typography.css index 558d2b4ce..3dd3bedfb 100644 --- a/packages/design/tailwind/css/typography.css +++ b/packages/design/tailwind/css/typography.css @@ -177,21 +177,28 @@ @apply gi-decoration-xs gi-underline gi-underline-offset-[0.2em] - gi-text-blue-700 - hover:gi-text-blue-800 - visited:gi-text-purple-700 - hover:gi-decoration-lg + gi-text-blue-700; +} + +.gi-link:not([aria-current='page']) { + @apply hover:gi-decoration-lg focus:gi-no-underline focus:gi-rounded-sm - focus:gi-text-blue-800 focus:gi-shadow-[0_0_0_2px_var(--gieds-color-gray-950),0_0_0_5px_var(--gieds-color-yellow-400)] focus-visible:gi-shadow-[0_0_0_2px_var(--gieds-color-gray-950),0_0_0_5px_var(--gieds-color-yellow-400)] - focus-visible:gi-text-blue-800 focus-visible:gi-no-underline focus-visible:gi-rounded-sm focus-visible:gi-outline-none; } +.gi-link[aria-current='page'] { + @apply gi-text-gray-700 gi-pointer-events-none gi-no-underline focus-visible:gi-outline-none focus-visible:gi-shadow-none; +} + +.gi-link:not(.gi-link-inherit) { + @apply hover:gi-text-blue-800 visited:gi-text-purple-700 focus:gi-text-blue-800 focus-visible:gi-text-blue-800; +} + .gi-link-sm { @apply gi-text-sm; } diff --git a/packages/html/ds/src/breadcrumbs/breadcrumbs.html b/packages/html/ds/src/breadcrumbs/breadcrumbs.html index 3abcd87aa..90ebbcc51 100644 --- a/packages/html/ds/src/breadcrumbs/breadcrumbs.html +++ b/packages/html/ds/src/breadcrumbs/breadcrumbs.html @@ -1,18 +1,29 @@ -