generated from nl-design-system/example
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,184 additions
and
1,287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@utrecht/button-react": major | ||
--- | ||
|
||
Add `@utrecht/button-react` package. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/component-library-react/jest-component.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* eslint-env node */ | ||
import nextJest from 'next/jest.js'; | ||
import { dirname } from 'node:path'; | ||
|
||
export const createJestConfig = (path) => { | ||
// Next Jest config is great for Jest 27 + React + TypeScript, so let's use that as basis | ||
const createJestConfig = nextJest({ | ||
dir: dirname(new URL(path).pathname), | ||
}); | ||
|
||
const customJestConfig = { | ||
// Add more setup options before each test is run | ||
// setupFilesAfterEnv: ['<rootDir>/jest.setup.js'], | ||
// if using TypeScript with a baseUrl set to the root directory then you need the below for alias' to work | ||
moduleDirectories: ['node_modules', '<rootDir>/'], | ||
testEnvironment: 'jest-environment-jsdom', | ||
testPathIgnorePatterns: ['/dist/'], | ||
// transformIgnorePatterns: ['node_modules/(?!@utrecht/web-component-library-react)'], | ||
}; | ||
|
||
return createJestConfig(customJestConfig); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/component-library-react/packages/button-react/jest.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { createJestConfig } from '../../jest-component.config.mjs'; | ||
|
||
export default createJestConfig(import.meta.url); |
41 changes: 41 additions & 0 deletions
41
packages/component-library-react/packages/button-react/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"version": "0.0.0", | ||
"author": "Community for NL Design System", | ||
"description": "Button component for the Municipality of Utrecht based on the NL Design System architecture", | ||
"license": "EUPL-1.2", | ||
"name": "@utrecht/button-react", | ||
"main": "./dist/index.cjs.js", | ||
"module": "./dist/index.esm.js", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist/", | ||
"src/" | ||
], | ||
"sideEffects": false, | ||
"scripts": { | ||
"build": "rollup -c ./rollup.config.mjs", | ||
"clean": "rimraf dist", | ||
"test": "mkdir -p pages && NODE_OPTIONS=--experimental-vm-modules jest --verbose" | ||
}, | ||
"devDependencies": { | ||
"@utrecht/button-css": "workspace:*", | ||
"jest": "29.7.0", | ||
"rollup": "4.18.0" | ||
}, | ||
"keywords": [ | ||
"nl-design-system" | ||
], | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git+ssh", | ||
"url": "git@github.com:nl-design-system/utrecht.git", | ||
"directory": "packages/component-library-react/packages/button-react" | ||
}, | ||
"peerDependencies": { | ||
"@babel/runtime": "^7.23.6", | ||
"react": "18", | ||
"react-dom": "18" | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/component-library-react/packages/button-react/rollup.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { createComponentPackageConfig } from '../../rollup-component-package.mjs'; | ||
|
||
export default createComponentPackageConfig(import.meta.url); |
9 changes: 9 additions & 0 deletions
9
packages/component-library-react/packages/button-react/src/css.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** | ||
* @license EUPL-1.2 | ||
* Copyright (c) 2020-2025 Frameless B.V. | ||
* Copyright (c) 2021-2025 Gemeente Utrecht | ||
*/ | ||
|
||
import '@utrecht/button-css/src/index.scss'; | ||
|
||
export * from './index'; |
8 changes: 7 additions & 1 deletion
8
...mponent-library-react/src/Button.test.tsx → .../packages/button-react/src/index.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
packages/component-library-react/packages/button-react/src/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* @license EUPL-1.2 | ||
* Copyright (c) 2020-2025 Frameless B.V. | ||
* Copyright (c) 2021-2025 Gemeente Utrecht | ||
*/ | ||
|
||
import clsx from 'clsx'; | ||
import { ButtonHTMLAttributes, ForwardedRef, forwardRef, PropsWithChildren } from 'react'; | ||
|
||
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> { | ||
appearance?: string; | ||
busy?: boolean; | ||
hint?: string; | ||
pressed?: boolean; | ||
} | ||
|
||
export const Button = forwardRef( | ||
( | ||
{ | ||
appearance, | ||
busy, | ||
disabled, | ||
children, | ||
className, | ||
hint, | ||
pressed, | ||
type, | ||
...restProps | ||
}: PropsWithChildren<ButtonProps>, | ||
ref: ForwardedRef<HTMLButtonElement>, | ||
) => { | ||
return ( | ||
<button | ||
ref={ref} | ||
className={clsx( | ||
'utrecht-button', | ||
busy && 'utrecht-button--busy', | ||
disabled && 'utrecht-button--disabled', | ||
type === 'submit' && 'utrecht-button--submit', | ||
appearance === 'primary-action-button' && 'utrecht-button--primary-action', | ||
appearance === 'secondary-action-button' && 'utrecht-button--secondary-action', | ||
appearance === 'subtle-button' && 'utrecht-button--subtle', | ||
hint === 'danger' && 'utrecht-button--danger', | ||
hint === 'warning' && 'utrecht-button--warning', | ||
hint === 'ready' && 'utrecht-button--ready', | ||
pressed === true && 'utrecht-button--pressed', | ||
className, | ||
)} | ||
aria-busy={busy || undefined} | ||
aria-pressed={typeof pressed === 'boolean' ? pressed : undefined} | ||
disabled={disabled} | ||
type={type || 'button'} | ||
{...restProps} | ||
> | ||
{children} | ||
</button> | ||
); | ||
}, | ||
); | ||
|
||
Button.displayName = 'Button'; | ||
|
||
export const PrimaryActionButton = ({ ...args }) => { | ||
return <Button {...args} appearance="primary-action-button" />; | ||
}; | ||
|
||
PrimaryActionButton.displayName = 'PrimaryActionButton'; | ||
|
||
export const SecondaryActionButton = ({ ...args }) => { | ||
return <Button {...args} appearance="secondary-action-button" />; | ||
}; | ||
|
||
SecondaryActionButton.displayName = 'SecondaryActionButton'; | ||
|
||
export const SubtleButton = ({ ...args }) => { | ||
return <Button {...args} appearance="subtle-button" />; | ||
}; | ||
|
||
SubtleButton.displayName = 'SubtleButton'; |
8 changes: 8 additions & 0 deletions
8
packages/component-library-react/packages/button-react/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "./src/" | ||
}, | ||
"include": ["src/**/*.ts", "src/**/*.tsx"], | ||
"exclude": ["**/node_modules/*", "**/*.test.ts", "**/*.test.tsx"] | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/component-library-react/packages/button-react/tsconfig.test.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"noEmit": true | ||
}, | ||
"include": ["src/**/*.ts", "src/**/*.tsx"], | ||
"exclude": ["**/node_modules/*"] | ||
} |
106 changes: 106 additions & 0 deletions
106
packages/component-library-react/rollup-component-package.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import babel from '@rollup/plugin-babel'; | ||
import commonjs from '@rollup/plugin-commonjs'; | ||
import json from '@rollup/plugin-json'; | ||
import resolve from '@rollup/plugin-node-resolve'; | ||
import { readFileSync } from 'fs'; | ||
import filesize from 'rollup-plugin-filesize'; | ||
import nodeExternal from 'rollup-plugin-node-externals'; | ||
import nodePolyfills from 'rollup-plugin-node-polyfills'; | ||
import peerDepsExternal from 'rollup-plugin-peer-deps-external'; | ||
import postcss from 'rollup-plugin-postcss'; | ||
import typescript from 'rollup-plugin-typescript2'; | ||
|
||
export const createComponentPackageConfig = (path) => { | ||
const packagePath = new URL('./package.json', path).pathname; | ||
const packageJson = JSON.parse(readFileSync(packagePath, 'utf8')); | ||
|
||
const outputGlobals = { | ||
react: 'React', | ||
'react-dom': 'ReactDOM', | ||
}; | ||
|
||
/** | ||
* @type {import('rollup').RollupOptions} | ||
*/ | ||
return [ | ||
{ | ||
input: new URL('./src/index.tsx', path).pathname, | ||
output: [ | ||
{ | ||
file: packageJson.main, | ||
format: 'cjs', | ||
sourcemap: true, | ||
globals: outputGlobals, | ||
}, | ||
{ | ||
file: packageJson.module, | ||
format: 'esm', | ||
sourcemap: true, | ||
globals: outputGlobals, | ||
}, | ||
], | ||
plugins: [ | ||
peerDepsExternal(), | ||
nodeExternal(), | ||
resolve({ browser: true }), | ||
commonjs({ | ||
include: /node_modules/, | ||
}), | ||
nodePolyfills(), | ||
typescript({ includeDependencies: false }), | ||
json(), | ||
babel({ | ||
presets: ['@babel/preset-react'], | ||
babelHelpers: 'runtime', | ||
exclude: ['node_modules/**', 'dist/**'], | ||
extensions: ['.ts', '.tsx'], | ||
inputSourceMap: true, | ||
plugins: ['@babel/plugin-transform-runtime'], | ||
}), | ||
filesize(), | ||
], | ||
}, | ||
{ | ||
input: new URL('./src/index.tsx', path).pathname, | ||
output: [ | ||
{ | ||
file: 'dist/css.js', | ||
format: 'cjs', | ||
sourcemap: true, | ||
globals: outputGlobals, | ||
}, | ||
{ | ||
file: 'dist/css.mjs', | ||
format: 'esm', | ||
sourcemap: true, | ||
globals: outputGlobals, | ||
}, | ||
], | ||
external: [/@babel\/runtime/, 'react-dom', 'react'], | ||
plugins: [ | ||
peerDepsExternal({ includeDependencies: true }), | ||
nodeExternal(), | ||
resolve({ browser: true }), | ||
commonjs({ | ||
include: /node_modules/, | ||
}), | ||
nodePolyfills(), | ||
postcss({ | ||
extensions: ['.css', '.scss'], | ||
minimize: true, | ||
}), | ||
typescript({ includeDependencies: false }), | ||
json(), | ||
babel({ | ||
presets: ['@babel/preset-react'], | ||
babelHelpers: 'runtime', | ||
exclude: ['node_modules/**', 'dist/**'], | ||
extensions: ['.ts', '.tsx'], | ||
inputSourceMap: true, | ||
plugins: ['@babel/plugin-transform-runtime'], | ||
}), | ||
filesize(), | ||
], | ||
}, | ||
]; | ||
}; |
Oops, something went wrong.