Skip to content

Commit

Permalink
feat(react): add PdsIcon helper (#126)
Browse files Browse the repository at this point in the history
* feat(react): add PdsIcon helper

* fix: include custom-elements in stencil.config

* chore: add storybook-static to gitignore
  • Loading branch information
ju-Skinner authored Dec 14, 2023
1 parent b07dbb5 commit 066cacc
Show file tree
Hide file tree
Showing 17 changed files with 236 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ docs.json
loader/
www/

storybook-static/
storybook-static

# IDEs and editors
.idea/
Expand Down
2 changes: 2 additions & 0 deletions libs/core/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
dist/
www/
loader/
components/

scripts/**/*.js

Expand All @@ -27,3 +28,4 @@ $RECYCLE.BIN/
Thumbs.db
UserInterfaceState.xcuserstate
.env

2 changes: 1 addition & 1 deletion libs/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"test.watch": "stencil test --spec --e2e --watchAll --coverage"
},
"dependencies": {
"@pine-ds/icons": "2.0.2",
"@pine-ds/icons": "3.3.0-rc.0",
"@stencil/core": "^4.8.1",
"sortablejs": "^1.15.0"
},
Expand Down
2 changes: 2 additions & 0 deletions libs/core/scripts/custom-elements/custom-elements.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './index';
export * from '../dist/types/interface';
9 changes: 9 additions & 0 deletions libs/core/scripts/custom-elements/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@pine-ds/core/components",
"version": "0.0.0",
"description": "Pine Components exported as custom elements, extending HTMLElement.",
"main": "./index.js",
"types": "./custom-elements.d.ts",
"private": true,
"sideEffects": false
}
5 changes: 4 additions & 1 deletion libs/core/scripts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
"module": "commonjs",
"resolveJsonModule": true,
"target": "es2017",
}
},
"exclude": [
"custom-elements"
]
}
22 changes: 14 additions & 8 deletions libs/core/stencil.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Config } from '@stencil/core';
import { reactOutputTarget } from '@stencil/react-output-target';

// @ts-ignore
// Plugins
import { sass } from '@stencil/sass';

Expand All @@ -19,8 +18,12 @@ export const config: Config = {
},
{
type: 'dist-custom-elements',
autoDefineCustomElements: true,
generateTypeDeclarations: true,
dir: 'components',
copy: [{
src: '../scripts/custom-elements',
dest: 'components',
warn: true
}],
includeGlobalScripts: false
},
{
Expand All @@ -37,12 +40,15 @@ export const config: Config = {
},
reactOutputTarget({
componentCorePackage: '@pine-ds/core',
includeDefineCustomElements: true,
includePolyfills: true,
proxiesFile: '../../libs/react/src/components/proxies.ts',
includeImportCustomElements: true,
includePolyfills: false,
includeDefineCustomElements: false,
proxiesFile: '../react/src/components/proxies.ts',
excludeComponents: [
'pds-icon'
]
}),
],
buildEs5: 'prod',
plugins: [sass()],
taskQueue: 'async',
plugins: [sass()]
};
11 changes: 10 additions & 1 deletion libs/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,14 @@
"target": "es2017",
},
"include": ["src", "scripts"],
"exclude": ["node_modules", "**/*.spec.ts", "**/*.spec.tsx", "**/*.e2e.ts", "**/*.stories.mdx", "**/*.stories.ts", "**/*.stories.tsx"]
"exclude": [
"node_modules",
"**/*.spec.ts",
"**/*.spec.tsx",
"**/*.e2e.ts",
"**/*.stories.mdx",
"**/*.stories.ts",
"**/*.stories.tsx",
"scripts/custom-elements"
]
}
14 changes: 7 additions & 7 deletions libs/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
],
"homepage": "https://github.com/kajabi/pine/tree/main#readme",
"sideEffects": false,
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/types/index.d.ts",
"repository": {
"type": "git",
"url": "git+https://github.com/Kajabi/pine.git"
Expand All @@ -32,15 +32,15 @@
"scripts": {
"build": "npm run clean && npm run compile",
"clean": "rm -rf dist",
"compile": "npm run tsc",
"tsc": "tsc -p .",
"rollup": "rollup -c"
"compile": "rollup -c",
"tsc": "tsc -p ."
},
"dependencies": {
"@pine-ds/core": "*",
"@pine-ds/icons": "2.0.2"
"@pine-ds/icons": "3.3.0-rc.0"
},
"devDependencies": {
"@rollup/plugin-typescript": "^11.1.5",
"@testing-library/jest-dom": "^6.1.3",
"@types/jest": "^29.1.2",
"@types/node": "^18.8.4",
Expand Down
18 changes: 18 additions & 0 deletions libs/react/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import typescript from '@rollup/plugin-typescript';

export default {
input: 'src/index.ts',
output: [
{
dir: 'dist/',
entryFileNames: '[name].js',
chunkFileNames: '[name]-[hash].js',
format: 'es',
sourcemap: true,
}
],
external: (id) => !/^(\.|\/)/.test(id),
plugins: [
typescript(),
],
};
45 changes: 45 additions & 0 deletions libs/react/src/components/PdsIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React, { PropsWithChildren } from 'react';

import { PdsReactProps } from './PdsReactProps';
import { PdsIconInner } from './inner-proxies';

import { createForwardRef } from './react-component-lib/utils';

interface PdsIconProps {
color?: string;
icon?: string;
name?: string;
size?: string;
}

type InternalProps = PropsWithChildren<
PdsIconProps & {
forwardedRef?: React.ForwardedRef<HTMLPdsIconElement>;
}
>;

class PdsIconContainer extends React.PureComponent<InternalProps> {
constructor(props: InternalProps) {
super(props);
if (this.props.name) {
console.warn(
'In Pine React, you import icons from "@pine-ds/icons" and set the icon you imported to the "icon" property. Setting the "name" property has no effect.'
);
}
}

render() {
const { icon, ...rest } = this.props;

return (
<PdsIconInner ref={this.props.forwardedRef} icon={icon} {...rest}>
{this.props.children}
</PdsIconInner>
);
}
}

export const PdsIcon = createForwardRef<PdsIconProps & PdsReactProps, HTMLPdsIconElement>(
PdsIconContainer,
'PdsIcon'
);
4 changes: 4 additions & 0 deletions libs/react/src/components/PdsReactProps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface PdsReactProps {
className?: string;
style?: { [key: string]: any };
}
12 changes: 12 additions & 0 deletions libs/react/src/components/inner-proxies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { JSX as PdsIconsJSX } from '@pine-ds/icons';
import { defineCustomElement as definePdsIcon } from '@pine-ds/icons/components/pds-icon.js';

import { createReactComponent } from './react-component-lib';

// @pine-ds/icons
export const PdsIconInner = /*@__PURE__*/ createReactComponent<PdsIconsJSX.PdsIcon, HTMLPdsIconElement>(
'pds-icon',
undefined,
undefined,
definePdsIcon
);
62 changes: 39 additions & 23 deletions libs/react/src/components/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,44 @@
/* auto-generated react proxies */
import { createReactComponent } from './react-component-lib';

import type { JSX } from '@pine-ds/core';
import type { JSX } from '@pine-ds/core/components';

import { applyPolyfills, defineCustomElements } from '@pine-ds/core/loader';
import { defineCustomElement as definePdsAvatar } from '@pine-ds/core/components/pds-avatar.js';
import { defineCustomElement as definePdsButton } from '@pine-ds/core/components/pds-button.js';
import { defineCustomElement as definePdsCheckbox } from '@pine-ds/core/components/pds-checkbox.js';
import { defineCustomElement as definePdsChip } from '@pine-ds/core/components/pds-chip.js';
import { defineCustomElement as definePdsCopytext } from '@pine-ds/core/components/pds-copytext.js';
import { defineCustomElement as definePdsDivider } from '@pine-ds/core/components/pds-divider.js';
import { defineCustomElement as definePdsImage } from '@pine-ds/core/components/pds-image.js';
import { defineCustomElement as definePdsInput } from '@pine-ds/core/components/pds-input.js';
import { defineCustomElement as definePdsLink } from '@pine-ds/core/components/pds-link.js';
import { defineCustomElement as definePdsProgress } from '@pine-ds/core/components/pds-progress.js';
import { defineCustomElement as definePdsRadio } from '@pine-ds/core/components/pds-radio.js';
import { defineCustomElement as definePdsSortable } from '@pine-ds/core/components/pds-sortable.js';
import { defineCustomElement as definePdsSortableItem } from '@pine-ds/core/components/pds-sortable-item.js';
import { defineCustomElement as definePdsSwitch } from '@pine-ds/core/components/pds-switch.js';
import { defineCustomElement as definePdsTab } from '@pine-ds/core/components/pds-tab.js';
import { defineCustomElement as definePdsTabpanel } from '@pine-ds/core/components/pds-tabpanel.js';
import { defineCustomElement as definePdsTabs } from '@pine-ds/core/components/pds-tabs.js';
import { defineCustomElement as definePdsTextarea } from '@pine-ds/core/components/pds-textarea.js';
import { defineCustomElement as definePdsTooltip } from '@pine-ds/core/components/pds-tooltip.js';

applyPolyfills().then(() => defineCustomElements());
export const PdsAvatar = /*@__PURE__*/createReactComponent<JSX.PdsAvatar, HTMLPdsAvatarElement>('pds-avatar');
export const PdsButton = /*@__PURE__*/createReactComponent<JSX.PdsButton, HTMLPdsButtonElement>('pds-button');
export const PdsCheckbox = /*@__PURE__*/createReactComponent<JSX.PdsCheckbox, HTMLPdsCheckboxElement>('pds-checkbox');
export const PdsChip = /*@__PURE__*/createReactComponent<JSX.PdsChip, HTMLPdsChipElement>('pds-chip');
export const PdsCopytext = /*@__PURE__*/createReactComponent<JSX.PdsCopytext, HTMLPdsCopytextElement>('pds-copytext');
export const PdsDivider = /*@__PURE__*/createReactComponent<JSX.PdsDivider, HTMLPdsDividerElement>('pds-divider');
export const PdsIcon = /*@__PURE__*/createReactComponent<JSX.PdsIcon, HTMLPdsIconElement>('pds-icon');
export const PdsImage = /*@__PURE__*/createReactComponent<JSX.PdsImage, HTMLPdsImageElement>('pds-image');
export const PdsInput = /*@__PURE__*/createReactComponent<JSX.PdsInput, HTMLPdsInputElement>('pds-input');
export const PdsLink = /*@__PURE__*/createReactComponent<JSX.PdsLink, HTMLPdsLinkElement>('pds-link');
export const PdsProgress = /*@__PURE__*/createReactComponent<JSX.PdsProgress, HTMLPdsProgressElement>('pds-progress');
export const PdsRadio = /*@__PURE__*/createReactComponent<JSX.PdsRadio, HTMLPdsRadioElement>('pds-radio');
export const PdsSortable = /*@__PURE__*/createReactComponent<JSX.PdsSortable, HTMLPdsSortableElement>('pds-sortable');
export const PdsSortableItem = /*@__PURE__*/createReactComponent<JSX.PdsSortableItem, HTMLPdsSortableItemElement>('pds-sortable-item');
export const PdsSwitch = /*@__PURE__*/createReactComponent<JSX.PdsSwitch, HTMLPdsSwitchElement>('pds-switch');
export const PdsTab = /*@__PURE__*/createReactComponent<JSX.PdsTab, HTMLPdsTabElement>('pds-tab');
export const PdsTabpanel = /*@__PURE__*/createReactComponent<JSX.PdsTabpanel, HTMLPdsTabpanelElement>('pds-tabpanel');
export const PdsTabs = /*@__PURE__*/createReactComponent<JSX.PdsTabs, HTMLPdsTabsElement>('pds-tabs');
export const PdsTextarea = /*@__PURE__*/createReactComponent<JSX.PdsTextarea, HTMLPdsTextareaElement>('pds-textarea');
export const PdsTooltip = /*@__PURE__*/createReactComponent<JSX.PdsTooltip, HTMLPdsTooltipElement>('pds-tooltip');
export const PdsAvatar = /*@__PURE__*/createReactComponent<JSX.PdsAvatar, HTMLPdsAvatarElement>('pds-avatar', undefined, undefined, definePdsAvatar);
export const PdsButton = /*@__PURE__*/createReactComponent<JSX.PdsButton, HTMLPdsButtonElement>('pds-button', undefined, undefined, definePdsButton);
export const PdsCheckbox = /*@__PURE__*/createReactComponent<JSX.PdsCheckbox, HTMLPdsCheckboxElement>('pds-checkbox', undefined, undefined, definePdsCheckbox);
export const PdsChip = /*@__PURE__*/createReactComponent<JSX.PdsChip, HTMLPdsChipElement>('pds-chip', undefined, undefined, definePdsChip);
export const PdsCopytext = /*@__PURE__*/createReactComponent<JSX.PdsCopytext, HTMLPdsCopytextElement>('pds-copytext', undefined, undefined, definePdsCopytext);
export const PdsDivider = /*@__PURE__*/createReactComponent<JSX.PdsDivider, HTMLPdsDividerElement>('pds-divider', undefined, undefined, definePdsDivider);
export const PdsImage = /*@__PURE__*/createReactComponent<JSX.PdsImage, HTMLPdsImageElement>('pds-image', undefined, undefined, definePdsImage);
export const PdsInput = /*@__PURE__*/createReactComponent<JSX.PdsInput, HTMLPdsInputElement>('pds-input', undefined, undefined, definePdsInput);
export const PdsLink = /*@__PURE__*/createReactComponent<JSX.PdsLink, HTMLPdsLinkElement>('pds-link', undefined, undefined, definePdsLink);
export const PdsProgress = /*@__PURE__*/createReactComponent<JSX.PdsProgress, HTMLPdsProgressElement>('pds-progress', undefined, undefined, definePdsProgress);
export const PdsRadio = /*@__PURE__*/createReactComponent<JSX.PdsRadio, HTMLPdsRadioElement>('pds-radio', undefined, undefined, definePdsRadio);
export const PdsSortable = /*@__PURE__*/createReactComponent<JSX.PdsSortable, HTMLPdsSortableElement>('pds-sortable', undefined, undefined, definePdsSortable);
export const PdsSortableItem = /*@__PURE__*/createReactComponent<JSX.PdsSortableItem, HTMLPdsSortableItemElement>('pds-sortable-item', undefined, undefined, definePdsSortableItem);
export const PdsSwitch = /*@__PURE__*/createReactComponent<JSX.PdsSwitch, HTMLPdsSwitchElement>('pds-switch', undefined, undefined, definePdsSwitch);
export const PdsTab = /*@__PURE__*/createReactComponent<JSX.PdsTab, HTMLPdsTabElement>('pds-tab', undefined, undefined, definePdsTab);
export const PdsTabpanel = /*@__PURE__*/createReactComponent<JSX.PdsTabpanel, HTMLPdsTabpanelElement>('pds-tabpanel', undefined, undefined, definePdsTabpanel);
export const PdsTabs = /*@__PURE__*/createReactComponent<JSX.PdsTabs, HTMLPdsTabsElement>('pds-tabs', undefined, undefined, definePdsTabs);
export const PdsTextarea = /*@__PURE__*/createReactComponent<JSX.PdsTextarea, HTMLPdsTextareaElement>('pds-textarea', undefined, undefined, definePdsTextarea);
export const PdsTooltip = /*@__PURE__*/createReactComponent<JSX.PdsTooltip, HTMLPdsTooltipElement>('pds-tooltip', undefined, undefined, definePdsTooltip);
1 change: 1 addition & 0 deletions libs/react/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./components/proxies";
export { defineCustomElements } from '@pine-ds/core/loader';
9 changes: 6 additions & 3 deletions libs/react/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,27 @@
"allowUnreachableCode": false,
"allowSyntheticDefaultImports": true,
"declaration": true,
"declarationDir": "./dist/types",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"esModuleInterop": true,
"lib": ["dom", "es2015"],
"module": "es2015",
"moduleResolution": "node",
"noImplicitAny": true,
"noImplicitAny": false,
"noImplicitReturns": true,
"noLib": false,
"noUnusedLocals": true,
"noUnusedParameters": true,
"outDir": "dist",
"removeComments": false,
"removeComments": true,
"skipLibCheck": true,
"sourceMap": true,
"jsx": "react",
"target": "es2015"
},
"include": ["src/**/*.ts", "src/**/*.tsx"],
"exclude": ["**/__tests__/**"],
"exclude": ["node_modules", "**/__tests__/**", "**/*.spec.ts"],
"compileOnSave": false,
"buildOnSave": false
}
Loading

0 comments on commit 066cacc

Please sign in to comment.