Skip to content

Commit

Permalink
Split out all utils into @near-pagoda/ui/utils to be importable in no…
Browse files Browse the repository at this point in the history
…n react environments
  • Loading branch information
calebjacob committed Dec 6, 2024
1 parent 9c8233e commit 14c933c
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 79 deletions.
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@near-pagoda/ui",
"version": "2.1.2",
"version": "3.0.0",
"description": "A React component library that implements the official NEAR design system.",
"license": "MIT",
"repository": {
Expand Down Expand Up @@ -37,23 +37,23 @@
"files": [
"dist"
],
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"types": "dist/index.d.ts",
"main": "./dist/index.cjs.js",
"module": "./dist/index.esm.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.esm.js"
},
"require": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.cjs.js"
}
"types": "./dist/index.d.ts",
"import": "./dist/index.esm.js",
"require": "./dist/index.cjs.js"
},
"./*.css": {
"import": "./dist/*.css",
"require": "./dist/*.css"
"./utils": {
"types": "./dist/utils/index.d.ts",
"import": "./dist/utils/index.esm.js",
"require": "./dist/utils/index.cjs.js"
},
"./styles.css": {
"import": "./dist/styles.css",
"require": "./dist/styles.css"
}
},
"peerDependencies": {
Expand Down
122 changes: 71 additions & 51 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,56 +12,76 @@ import { visualizer } from 'rollup-plugin-visualizer';
import concat from './rollup-plugin-concat.mjs';

/** @type {import('rollup').RollupOptions} */
const options = {
input: ['./src/index.ts'],
output: [
{
file: './dist/index.esm.js',
format: 'esm',
sourcemap: false,
inlineDynamicImports: true,
},
{
file: './dist/index.cjs.js',
format: 'cjs',
sourcemap: false,
inlineDynamicImports: true,
},
],
plugins: [
json(),
scss({
fileName: 'globals.css',
exclude: ['/**/*.module.scss'],
failOnError: true,
verbose: true,
outputStyle: 'compressed',
}),
peerDepsExternal(),
resolve({ browser: true }),
commonjs(),
typescript(),
terser(),
postcss({
extract: 'modules.css',
modules: true,
syntax: 'postcss-scss',
minimize: true,
plugins: [
postcssPresetEnv({
stage: 3,
features: {
'nesting-rules': true,
},
}),
],
}),
concat({
files: ['./dist/globals.css', './dist/modules.css'],
outputFile: './dist/styles.css',
}),
visualizer(),
],
};
const options = [
{
input: './src/index.ts',
output: [
{
file: './dist/index.esm.js',
format: 'esm',
sourcemap: false,
inlineDynamicImports: true,
},
{
file: './dist/index.cjs.js',
format: 'cjs',
sourcemap: false,
inlineDynamicImports: true,
},
],
plugins: [
json(),
scss({
fileName: 'globals.css',
exclude: ['/**/*.module.scss'],
failOnError: true,
verbose: true,
outputStyle: 'compressed',
}),
peerDepsExternal(),
resolve({ browser: true }),
commonjs(),
typescript(),
terser(),
postcss({
extract: 'modules.css',
modules: true,
syntax: 'postcss-scss',
minimize: true,
plugins: [
postcssPresetEnv({
stage: 3,
features: {
'nesting-rules': true,
},
}),
],
}),
concat({
files: ['./dist/globals.css', './dist/modules.css'],
outputFile: './dist/styles.css',
}),
visualizer(),
],
},
{
input: './src/utils/index.ts',
output: [
{
file: './dist/utils/index.esm.js',
format: 'esm',
sourcemap: false,
inlineDynamicImports: true,
},
{
file: './dist/utils/index.cjs.js',
format: 'cjs',
sourcemap: false,
inlineDynamicImports: true,
},
],
plugins: [peerDepsExternal(), resolve({ browser: true }), commonjs(), typescript(), terser()],
},
];

export default options;
10 changes: 0 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,6 @@ export { useTheme } from 'next-themes';
export * from './components/CookiePrompt/hooks';
export * from './hooks/debounce';

// Utils

export * from './utils/clipboard';
export * from './utils/error';
export * from './utils/input-handlers';
export * from './utils/merge-refs';
export * from './utils/number';
export * from './utils/theme';
export * from './utils/unreachable';

// Contexts

export { PagodaUiProvider } from './context/PagodaUi';
4 changes: 2 additions & 2 deletions src/utils/clipboard.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { openToast } from '../components/Toast';
import { openToast } from '../components/Toast/api';

export async function copyTextToClipboard(content: string, description?: string) {
try {
await navigator.clipboard.writeText(content);

openToast({
type: 'success',
title: 'Copied',
title: 'Copied To Clipboard',
description,
});
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { openToast } from '../components/Toast';
import { openToast } from '../components/Toast/api';

export function handleClientError({ error, title, description }: { error: any; title?: string; description?: string }) {
console.error(error);
Expand Down
7 changes: 7 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export * from './clipboard';
export * from './error';
export * from './input-handlers';
export * from './merge-refs';
export * from './number';
export * from './theme';
export * from './unreachable';

0 comments on commit 14c933c

Please sign in to comment.