-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Button): extracting Button and peers as a standalone package (#635)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced a new `ui-button` package, expanding the UI component library with button functionalities. - Added Tailwind CSS integration for improved styling capabilities. - **Bug Fixes** - Updated dependencies to ensure compatibility and performance improvements. - **Documentation** - Added README for the new `ui-button` package, detailing its purpose and usage. - **Refactor** - Updated import paths for button components across the UI component library to streamline access. - **Tests** - Enhanced test coverage for the `ButtonIcon` component to ensure proper rendering with specific props. - Improved error handling in the testing environment to catch critical React warnings. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
- Loading branch information
Showing
39 changed files
with
386 additions
and
15 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# @versini/ui-button | ||
|
||
This is a button component. |
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,49 @@ | ||
{ | ||
"name": "@versini/ui-button", | ||
"version": "0.0.0", | ||
"license": "MIT", | ||
"author": "Arno Versini", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"homepage": "https://github.com/aversini/ui-components", | ||
"repository": { | ||
"type": "git", | ||
"url": "[email protected]:aversini/ui-components.git" | ||
}, | ||
"type": "module", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"files": ["dist"], | ||
"scripts": { | ||
"build:check": "tsc", | ||
"build:js": "vite build", | ||
"build:types": "tsup", | ||
"build": "npm-run-all --serial clean build:check build:js build:types", | ||
"clean": "rimraf dist tmp", | ||
"dev:js": "vite build --watch --mode development", | ||
"dev:types": "tsup --watch src", | ||
"dev": "npm-run-all clean --parallel dev:js dev:types", | ||
"lint": "biome lint src", | ||
"start": "static-server dist --port 5173", | ||
"test:coverage:ui": "vitest --coverage --ui", | ||
"test:coverage": "vitest run --coverage", | ||
"test:watch": "vitest", | ||
"test": "vitest run" | ||
}, | ||
"peerDependencies": { | ||
"react": "^18.3.1", | ||
"react-dom": "^18.3.1" | ||
}, | ||
"devDependencies": { | ||
"@versini/ui-icons": "workspace:../ui-icons", | ||
"@versini/ui-styles": "workspace:../ui-styles" | ||
}, | ||
"dependencies": { | ||
"@tailwindcss/typography": "0.5.15", | ||
"@versini/ui-private": "workspace:../ui-private", | ||
"clsx": "2.1.1", | ||
"tailwindcss": "3.4.11" | ||
}, | ||
"sideEffects": ["**/*.css"] | ||
} |
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,6 @@ | ||
module.exports = { | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
}; |
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 @@ | ||
export const BUTTON_CLASSNAME = "av-button"; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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,6 @@ | ||
import { Button } from "./Button/Button"; | ||
import { ButtonIcon } from "./Button/ButtonIcon"; | ||
import { ButtonLink } from "./Button/ButtonLink"; | ||
import { ButtonSort as ButtonSort_private } from "./private/ButtonSort"; | ||
|
||
export { Button, ButtonIcon, ButtonLink, ButtonSort_private }; |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; |
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 @@ | ||
import "./index.css"; |
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 @@ | ||
/// <reference types="vite/client" /> |
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,7 @@ | ||
/** @type {import('tailwindcss').Config} */ | ||
|
||
import { twPlugin } from "@versini/ui-styles"; | ||
|
||
export default twPlugin.merge({ | ||
content: ["./index.html", "./src/**/*.{js,ts,jsx,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,26 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2020", | ||
"useDefineForClassFields": true, | ||
"lib": ["ES2020", "DOM", "DOM.Iterable"], | ||
"module": "ESNext", | ||
"skipLibCheck": true, | ||
"types": ["vitest/globals", "@testing-library/jest-dom"], | ||
|
||
/* Bundler mode */ | ||
"moduleResolution": "bundler", | ||
"allowImportingTsExtensions": true, | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"noEmit": true, | ||
"jsx": "react-jsx", | ||
|
||
/* Linting */ | ||
"strict": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noFallthroughCasesInSwitch": true | ||
}, | ||
"include": ["src"], | ||
"references": [{ "path": "./tsconfig.node.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,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"composite": true, | ||
"skipLibCheck": true, | ||
"module": "ESNext", | ||
"moduleResolution": "bundler", | ||
"allowSyntheticDefaultImports": true | ||
}, | ||
"include": ["./vite.config.ts", "./vitest.setup.ts"] | ||
} |
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,12 @@ | ||
import { defineConfig } from "tsup"; | ||
|
||
export default defineConfig({ | ||
format: "esm", | ||
entry: { | ||
index: "src/components/index.ts", | ||
}, | ||
outDir: "dist", | ||
dts: { | ||
only: true, | ||
}, | ||
}); |
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,113 @@ | ||
import path from "node:path"; | ||
import { resolve } from "node:path"; | ||
import { fileURLToPath } from "node:url"; | ||
|
||
import fs from "fs-extra"; | ||
import { glob } from "glob"; | ||
import { defineConfig } from "vite"; | ||
|
||
import { externalDependencies } from "../../configuration/vite.common"; | ||
|
||
const packageJson = fs.readJSONSync("package.json"); | ||
const copyrightYear = new Date(Date.now()).getFullYear(); | ||
const buildTime = new Date() | ||
.toLocaleString("en-US", { | ||
timeZone: "America/New_York", | ||
timeZoneName: "short", | ||
year: "numeric", | ||
month: "2-digit", | ||
day: "2-digit", | ||
hour: "2-digit", | ||
minute: "2-digit", | ||
}) | ||
.replace(/,/g, ""); | ||
const banner = `/*! | ||
${packageJson.name} v${packageJson.version} | ||
© ${copyrightYear} gizmette.com | ||
*/ | ||
try { | ||
if (!window.__VERSINI_UI_BUTTON__) { | ||
window.__VERSINI_UI_BUTTON__ = { | ||
version: "${packageJson.version}", | ||
buildTime: "${buildTime}", | ||
homepage: "${packageJson.homepage}", | ||
license: "${packageJson.license}", | ||
}; | ||
} | ||
} catch (error) { | ||
// nothing to declare officer | ||
} | ||
`; | ||
|
||
export default defineConfig(({ mode }) => { | ||
const isDev = mode === "development"; | ||
/** | ||
* Build a list of public files, which means all files in the | ||
* src/components/ComponentName folders. | ||
* Everything else will be moved to the chunk folder. | ||
*/ | ||
const input = isDev | ||
? {} | ||
: Object.fromEntries( | ||
glob | ||
.sync("src/**/*.{ts,tsx}") | ||
.filter((file) => { | ||
return file.match( | ||
/src\/components\/[A-Z][a-zA-Z]*\/[A-Z][a-zA-Z]*\.tsx/, | ||
) | ||
? file | ||
: null; | ||
}) | ||
.map((file) => { | ||
return [ | ||
// This remove `src/` as well as the file extension from each | ||
// file, so e.g. src/nested/foo.js becomes nested/foo | ||
path.relative( | ||
"src", | ||
file.slice(0, file.length - path.extname(file).length), | ||
), | ||
// This expands the relative paths to absolute paths, so e.g. | ||
// src/nested/foo becomes /project/src/nested/foo.js | ||
fileURLToPath(new URL(file, import.meta.url)), | ||
]; | ||
}), | ||
); | ||
|
||
return { | ||
build: { | ||
copyPublicDir: false, | ||
lib: { | ||
entry: resolve(__dirname, "src/components/index.ts"), | ||
formats: ["es"], | ||
name: "UIButton", | ||
}, | ||
rollupOptions: { | ||
input: { | ||
index: resolve(__dirname, "src/components/index.ts"), | ||
style: resolve(__dirname, "src/style.ts"), | ||
...input, | ||
}, | ||
treeshake: "smallest", | ||
external: externalDependencies, | ||
output: { | ||
compact: true, | ||
minifyInternalExports: false, | ||
assetFileNames: "style[extname]", | ||
entryFileNames: "[name].js", | ||
chunkFileNames: "chunks/[name].[hash].js", | ||
banner: (module) => { | ||
if (module?.facadeModuleId?.endsWith("src/components/index.ts")) { | ||
return banner; | ||
} | ||
}, | ||
}, | ||
}, | ||
}, | ||
esbuild: { | ||
supported: { | ||
"top-level-await": true, | ||
}, | ||
}, | ||
plugins: [], | ||
}; | ||
}); |
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,28 @@ | ||
/// <reference types="vitest" /> | ||
|
||
import { defineConfig, mergeConfig } from "vitest/config"; | ||
|
||
import viteConfig from "./vite.config"; | ||
|
||
export default defineConfig((configEnv) => | ||
mergeConfig( | ||
viteConfig(configEnv), | ||
defineConfig({ | ||
test: { | ||
globals: true, | ||
setupFiles: ["./vitest.setup.ts"], | ||
environment: "happy-dom", | ||
coverage: { | ||
include: ["src/**/*.ts", "src/**/*.tsx", "!src/style.ts"], | ||
provider: "v8", | ||
thresholds: { | ||
statements: 100, | ||
branches: 100, | ||
functions: 100, | ||
lines: 100, | ||
}, | ||
}, | ||
}, | ||
}), | ||
), | ||
); |
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,17 @@ | ||
import "@testing-library/jest-dom/vitest"; | ||
|
||
import util from "node:util"; | ||
|
||
const originalConsoleError = console.error; | ||
console.error = (...args: any) => { | ||
const message = util.format(...args); | ||
if ( | ||
/(Warning: validateDOMNesting|Invalid prop|Failed prop type|React does not recognize|Unknown event handler property)/gi.test( | ||
message, | ||
) | ||
) { | ||
throw new Error(message); | ||
} else { | ||
originalConsoleError.apply(console, [...args]); | ||
} | ||
}; |
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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import type { ButtonLinkProps } from "../Button/ButtonTypes"; | ||
import type { ButtonLinkProps } from "@versini/ui-button"; | ||
|
||
export type AnchorProps = ButtonLinkProps & | ||
React.AnchorHTMLAttributes<HTMLAnchorElement>; |
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: 2 additions & 1 deletion
3
packages/ui-components/src/components/Menu/__tests__/Menu.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
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
Oops, something went wrong.