Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build!: Allow direct imports and component normalization #2899

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0c8dcaf
initial
jpandersen87 Apr 17, 2024
81a1498
normalization pass
jpandersen87 Apr 17, 2024
86b859d
update exports
jpandersen87 Apr 17, 2024
9c052b5
fix attempt
jpandersen87 Apr 17, 2024
23746ea
use default output folder
jpandersen87 Apr 17, 2024
1a2b259
exports fix
jpandersen87 Apr 17, 2024
84b78bf
back-compat exports
jpandersen87 Apr 17, 2024
16d7f49
ongoing dual package experimentation
jpandersen87 Apr 25, 2024
9751dcc
git fix lowercase renames
jpandersen87 Apr 25, 2024
27658da
git more rename fixes
jpandersen87 Apr 25, 2024
eeea813
fix serverSideTest
jpandersen87 Apr 25, 2024
671b400
ongoing
jpandersen87 Apr 25, 2024
6d571d8
passes arethetypeswrong.github.io
jpandersen87 Apr 26, 2024
12cd860
gitignore fixes
jpandersen87 Apr 26, 2024
30e2e10
gitignore fixes
jpandersen87 Apr 26, 2024
3c7e35c
passes arethetypeswrong.github.io
jpandersen87 Apr 26, 2024
c01fb0b
fix script
jpandersen87 Apr 26, 2024
659db5c
build script
jpandersen87 Apr 26, 2024
5be422a
fix index, exports
jpandersen87 Apr 26, 2024
3d8dcf5
per-component client directives
jpandersen87 Apr 26, 2024
697ba08
cleanup
jpandersen87 Apr 26, 2024
51ded9b
Merge branch 'main' into tree-shaking
jpandersen87 Apr 26, 2024
0c5a760
fix storybook
jpandersen87 Apr 26, 2024
35c19d1
bugfix
jpandersen87 Apr 27, 2024
18c6558
cleanup
jpandersen87 Apr 27, 2024
47501b4
typescript `node16` mode
jpandersen87 Apr 27, 2024
a565bf9
cleanup
jpandersen87 Apr 27, 2024
f3f3710
ignore fixtures
jpandersen87 Apr 27, 2024
2866b9b
cleanup
jpandersen87 Apr 27, 2024
57f628c
icon utils, qol type exports on forwardref variants
jpandersen87 Apr 27, 2024
91571b8
fixes
jpandersen87 Apr 27, 2024
67ff63e
adjust forwardRef pattern
jpandersen87 Apr 27, 2024
c703146
test fix
jpandersen87 Apr 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18.15.0
18.19.1
9 changes: 5 additions & 4 deletions .storybook/USWDS.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { create } from '@storybook/theming/create';
import { create } from '@storybook/theming/create'

export default create({
brandTitle: 'U.S. Web Design System (USWDS)',
brandUrl: 'https://github.com/trussworks/react-uswds',
brandImage: '/uswds.svg',
brandImage: 'uswds.svg',
brandTarget: '_self',
base: 'light',

// Text
fontBase: "'Public Sans Web', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'",
fontBase:
"'Public Sans Web', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'",
textColor: '#1b1b1b',
inputTextColor: '#1b1b1b',
textInverseColor: '#ffffff',
Expand All @@ -22,4 +23,4 @@ export default create({
appBorderRadius: 4,
inputBorder: '#5c5c5c',
inputBorderRadius: 4,
});
})
2 changes: 1 addition & 1 deletion .storybook/custom-styles.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@forward '../src/styles/uswds-theme';
@forward '../libSrc/styles/uswds-theme';
@use 'uswds-core' as *;

// Add custom styles for storybook implementation
Expand Down
5 changes: 4 additions & 1 deletion .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import type { StorybookConfig } from '@storybook/react-vite'

const config: StorybookConfig = {
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
stories: [
'../libSrc/**/*.mdx',
'../libSrc/**/*.stories.@(js|jsx|mjs|ts|tsx)',
],
addons: [
'@storybook/addon-a11y',
'@storybook/addon-docs',
Expand Down
16 changes: 11 additions & 5 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import 'happo-plugin-storybook/register'

import '@uswds/uswds/css/uswds.css'
import '../src/styles/index.scss'
import '../libSrc/styles/index.scss'
import './custom-styles.scss'

import { INITIAL_VIEWPORTS } from '@storybook/addon-viewport'
import { Preview } from '@storybook/react';
import USWDS from './USWDS';
import { Preview } from '@storybook/react'
import USWDS from './USWDS'

const preview: Preview = {
parameters: {
Expand All @@ -20,9 +20,15 @@ const preview: Preview = {
showPanel: true,
storySort: {
method: 'alphabetical',
order: ['Welcome', 'Design tokens', 'Page Templates', 'Components', 'Other'],
order: [
'Welcome',
'Design tokens',
'Page Templates',
'Components',
'Other',
],
},
},
},
}
export default preview;
export default preview
3 changes: 0 additions & 3 deletions __mocks__/fileMock.js

This file was deleted.

1 change: 0 additions & 1 deletion __mocks__/svgrMock.js

This file was deleted.

2 changes: 2 additions & 0 deletions custom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ declare namespace globalThis {
MSStream: object
}
}

declare module '@uswds/compile'
29 changes: 29 additions & 0 deletions gulpfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import uswds from '@uswds/compile'

uswds.settings.version = 3
uswds.paths.dist = {
...uswds.paths.dist,
theme: 'lib/dist/assets/uswds/sass',
img: 'lib/dist/assets/uswds/img',
fonts: 'lib/dist/assets/uswds/fonts',
js: 'lib/dist/assets/uswds/js',
css: 'lib/dist/assets/uswds/css',
}

export {
settings,
paths,
sprite,
copyTheme,
copyFonts,
copyImages,
copyJS,
copyAssets,
copyAll,
compileSass,
compileIcons,
compile,
updateUswds,
init,
watch,
} from '@uswds/compile'
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import { Alert } from './Alert'

import { Button } from '../Button/Button'
import Alert from './Alert.js'
import Button from '../Button/ButtonForwardRef.js'

export default {
title: 'Components/Alert',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react'
import { render } from '@testing-library/react'

import { Alert } from './Alert'
import { HeadingLevel } from '../../types/headingLevel'
import Alert from './Alert.js'
import type { HeadingLevel } from '../../types/headingLevel.js'

describe('Alert component', () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react'
import classnames from 'classnames'

import { HeadingLevel } from '../../types/headingLevel'
import type { HeadingLevel } from '../../types/headingLevel.js'

import styles from './Alert.module.scss'

type AlertProps = {
type: 'success' | 'warning' | 'error' | 'info'
export interface BaseAlertProps {
type?: 'success' | 'warning' | 'error' | 'info'
heading?: React.ReactNode
headingLevel: HeadingLevel
children?: React.ReactNode
Expand All @@ -16,7 +16,9 @@ type AlertProps = {
validation?: boolean
}

export const Alert = ({
export type AlertProps = BaseAlertProps & JSX.IntrinsicElements['div']

const Alert = ({
type,
heading,
headingLevel,
Expand All @@ -27,7 +29,7 @@ export const Alert = ({
className,
validation,
...props
}: AlertProps & React.HTMLAttributes<HTMLDivElement>): React.ReactElement => {
}: AlertProps): React.ReactElement => {
const classes = classnames(
'usa-alert',
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import { Button } from './Button'

import Button from './Button.js'

export default {
title: 'Components/Button',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react'
import React, { createRef } from 'react'
import { render, fireEvent } from '@testing-library/react'

import Button from './Button.js'

vi.mock('../../deprecation')
import { Button } from './Button'

describe('Button component', () => {
beforeEach(() => {
Expand All @@ -14,6 +15,17 @@ describe('Button component', () => {
expect(queryByTestId('button')).toBeInTheDocument()
})

it('renders ref', () => {
const testRef = createRef<HTMLButtonElement>()
const { queryByTestId } = render(
<Button type="button" _ref={testRef}>
Click Me
</Button>
)
expect(queryByTestId('button')).toBeInTheDocument()
expect(testRef.current).toBeInstanceOf(HTMLButtonElement)
})

describe('renders uswds classes', () => {
it('usa-button', () => {
const { queryByTestId } = render(<Button type="button">Click Me</Button>)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react'
import classnames from 'classnames'

export type ButtonProps = {
type: 'button' | 'submit' | 'reset'
export interface BaseButtonProps {
type?: 'button' | 'submit' | 'reset'
children: React.ReactNode
secondary?: boolean
base?: boolean
Expand All @@ -11,10 +11,14 @@ export type ButtonProps = {
inverse?: boolean
size?: 'big'
unstyled?: boolean
// TODO: Remove underscore, or remove property entirely if handled by new React 19 typing
_ref?: React.ForwardedRef<HTMLButtonElement>
}

export const Button = ({
type,
export type ButtonProps = BaseButtonProps & JSX.IntrinsicElements['button']

function Button({
type = 'button',
children,
secondary,
base,
Expand All @@ -23,10 +27,10 @@ export const Button = ({
inverse,
size,
unstyled,
onClick,
className,
_ref,
...defaultProps
}: ButtonProps & JSX.IntrinsicElements['button']): React.ReactElement => {
}: ButtonProps): React.ReactElement {
const classes = classnames(
'usa-button',
{
Expand All @@ -46,8 +50,8 @@ export const Button = ({
<button
type={type}
className={classes}
onClick={onClick}
data-testid="button"
ref={_ref}
{...defaultProps}>
{children}
</button>
Expand Down
13 changes: 13 additions & 0 deletions libSrc/components/Button/ButtonForwardRef.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React, { forwardRef } from 'react'
import Button, { ButtonProps } from './Button.js'

const ButtonForwardRef = forwardRef(function ButtonForwardRef(
props: ButtonProps,
ref: React.ForwardedRef<HTMLButtonElement>
) {
return <Button _ref={ref} {...props} />
})

export type { BaseButtonProps, ButtonProps } from './Button.js'

export default ButtonForwardRef
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react'
import { ButtonGroup } from './ButtonGroup'
import { Button } from '../Button/Button'
import { Link } from '../Link/Link'

import ButtonGroup from './ButtonGroup.js'
import Button from '../Button/ButtonForwardRef.js'
import Link from '../Link/Link.js'

export default {
title: 'Components/Button groups',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import { render } from '@testing-library/react'

import { ButtonGroup } from './ButtonGroup'
import ButtonGroup from './ButtonGroup.js'

describe('ButtonGroup component', () => {
it('renders without errors', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import React from 'react'
import classnames from 'classnames'

type ButtonGroupProps = {
export interface BaseButtonGroupProps {
children: React.ReactNode
className?: string
type?: 'default' | 'segmented'
} & JSX.IntrinsicElements['ul']
}

export type ButtonGroupProps = BaseButtonGroupProps &
JSX.IntrinsicElements['ul']

export const ButtonGroup = ({
const ButtonGroup = ({
className,
children,
type = 'default',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'

import { Icon } from './Icons'
import Icon from './Icon.js'

type StorybookArgs = {
size: 3 | 4 | 5 | 6 | 7 | 8 | 9
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import { render, screen } from '@testing-library/react'

import { Icon } from './Icons'
import Icon from './Icon.js'

describe('Icon component', () => {
it('renders without errors', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ import ZoomInSvg from '@uswds/uswds/img/usa-icons/zoom_in.svg?svgr'
import ZoomOutMapSvg from '@uswds/uswds/img/usa-icons/zoom_out_map.svg?svgr'
import ZoomOutSvg from '@uswds/uswds/img/usa-icons/zoom_out.svg?svgr'

import { makeUSWDSIcon, IconProps } from './Icon'
import { makeUSWDSIcon, type IconProps } from './utils.js'
import React from 'react'

export class Icon {
class Icon {
public static AccessibilityNew: React.ComponentType<IconProps> =
makeUSWDSIcon(AccessibilityNewSvg)

Expand Down Expand Up @@ -926,4 +926,6 @@ export class Icon {
makeUSWDSIcon(ZoomOutSvg)
}

export type { BaseIconProps, IconProps } from './utils.js'

export default Icon
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'

import { Icon } from './Icons'
import Icon from './Icon.js'

type StorybookArgs = {
size: 3 | 4 | 5 | 6 | 7 | 8 | 9
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react'
import classnames from 'classnames'

interface USWDSIconProps {
export interface BaseIconProps {
focusable?: boolean
role?: string
size?: 3 | 4 | 5 | 6 | 7 | 8 | 9
className?: string
}

export type IconProps = USWDSIconProps & JSX.IntrinsicElements['svg']
export type IconProps = BaseIconProps & JSX.IntrinsicElements['svg']

export const makeUSWDSIcon = (
Component: React.ComponentType<IconProps>
Expand Down
Loading
Loading