Browse Source

add SSR support with `rollup-preset-solid` and JSX refactor (#1493)

* refactor(icons-solidjs): update SVG paths for consistency and remove unused component

- Modified SVG path for the accessible icon to ensure consistency in syntax.
- Removed the `createSolidComponent.ts` file as it is no longer needed.

* refactor(icons-solidjs): update package configuration and simplify rollup setup

- Updated package.json to improve module exports and types definitions.
- Simplified rollup configuration by replacing custom setup with rollup-preset-solid for better maintainability.
pull/1484/head
Paweł Kuna 7 months ago
committed by GitHub
parent
commit
bb266e972f
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 20
      packages/icons-solidjs/package.json
  2. 43
      packages/icons-solidjs/rollup.config.js
  3. 50
      packages/icons-solidjs/src/createSolidComponent.ts
  4. 56
      packages/icons-solidjs/src/createSolidComponent.tsx
  5. 10
      packages/icons-solidjs/test.spec.jsx

20
packages/icons-solidjs/package.json

@ -22,18 +22,28 @@
"amdName": "TablerIconsSolidjs",
"exports": {
".": {
"solid": "./dist/source/tabler-icons-solidjs.js",
"import": {
"types": "./dist/tabler-icons-solidjs.d.ts",
"types": "./dist/types/tabler-icons-solidjs.d.ts",
"default": "./dist/esm/tabler-icons-solidjs.js"
},
"browser": {
"types": "./dist/types/tabler-icons-solidjs.d.ts",
"default": "./dist/esm/tabler-icons-solidjs.js"
},
"require": {
"types": "./dist/cjs/tabler-icons-solidjs.d.cts",
"default": "./dist/cjs/tabler-icons-solidjs.cjs"
"types": "./dist/types/tabler-icons-solidjs.d.ts",
"default": "./dist/cjs/tabler-icons-solidjs.js"
},
"node": {
"default": "./dist/cjs/tabler-icons-solidjs.js",
"types": "./dist/types/tabler-icons-solidjs.d.ts"
}
}
},
"main": "./dist/cjs/tabler-icons-solidjs.cjs",
"types": "./dist/cjs/tabler-icons-solidjs.d.cts",
"main": "./dist/cjs/tabler-icons-solidjs.js",
"module": "./dist/esm/tabler-icons-solidjs.js",
"types": "./dist/types/tabler-icons-solidjs.d.ts",
"files": [
"dist"
],

43
packages/icons-solidjs/rollup.config.js

@ -1,38 +1,7 @@
import fs from 'fs'
import { getRollupConfig } from '../../.build/rollup-plugins.mjs'
import dts from "rollup-plugin-dts";
import withSolid from 'rollup-preset-solid';
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8'))
const outputFileName = 'tabler-icons-solidjs';
const inputs = ['./src/tabler-icons-solidjs.ts'];
const bundles = [
{
format: 'cjs',
extension: 'cjs',
inputs,
},
{
format: 'esm',
inputs,
preserveModules: true,
extension: 'js',
},
];
export default [
{
input: inputs[0],
output: [
{
file: `dist/${outputFileName}.d.ts`,
format: 'es',
},
],
plugins: [dts()],
},
...getRollupConfig(pkg, outputFileName, bundles, {
'solid-js': 'solid-js',
'solid-js/h': 'solid-js/h',
})
];
export default withSolid({
input: 'src/tabler-icons-solidjs.ts',
targets: ['esm', 'cjs'],
printInstructions: false,
});

50
packages/icons-solidjs/src/createSolidComponent.ts

@ -1,50 +0,0 @@
import { JSX } from 'solid-js/jsx-runtime';
import defaultAttributes from './defaultAttributes';
import { splitProps } from 'solid-js';
import h from 'solid-js/h';
import { IconNode, IconProps } from './types';
const createSolidComponent = (
type: 'outline' | 'filled',
iconName: string,
iconNamePascal: string,
iconNode: IconNode,
) => {
const Component = (props: IconProps): JSX.Element => {
const [localProps, rest] = splitProps(props, ['color', 'size', 'stroke', 'title', 'children', 'class']),
attributes = defaultAttributes[type];
const svgProps = {
...attributes,
width: () => (localProps.size != null ? localProps.size : attributes.width),
height: () => (localProps.size != null ? localProps.size : attributes.height),
title: () => localProps.title != null ? localProps.title : undefined,
...(type === 'filled'
? {
fill: () => (localProps.color != null ? localProps.color : 'currentColor'),
}
: {
stroke: () => (localProps.color != null ? localProps.color : 'currentColor'),
'stroke-width': () =>
localProps.stroke != null ? localProps.stroke : attributes['stroke-width'],
}),
class: () =>
`tabler-icon tabler-icon-${iconName} ${localProps.class != null ? localProps.class : ''}`,
};
return h(
'svg',
[svgProps, rest],
[
localProps.title && h('title', {}, localProps.title),
...iconNode.map(([tag, attrs]) => h(tag, attrs)),
localProps.children
],
) as unknown as JSX.Element;
};
Component.displayName = `${iconNamePascal}`;
return Component;
};
export default createSolidComponent;

56
packages/icons-solidjs/src/createSolidComponent.tsx

@ -0,0 +1,56 @@
import { JSX } from 'solid-js/jsx-runtime';
import defaultAttributes from './defaultAttributes';
import { splitProps } from 'solid-js';
import { Dynamic } from 'solid-js/web';
import { IconNode, IconProps } from './types';
const createSolidComponent = (
type: 'outline' | 'filled',
iconName: string,
iconNamePascal: string,
iconNode: IconNode,
) => {
const Component = (props: IconProps): JSX.Element => {
const [localProps, rest] = splitProps(props, [
'color',
'size',
'stroke',
'strokeWidth',
'title',
'children',
'class',
]);
const attributes = defaultAttributes[type];
const strokeValue = localProps.stroke ?? localProps.strokeWidth;
return (
<svg
{...attributes}
{...rest}
width={localProps.size != null ? localProps.size : attributes.width}
height={localProps.size != null ? localProps.size : attributes.height}
class={`tabler-icon tabler-icon-${iconName} ${localProps.class != null ? localProps.class : ''}`}
{...(type === 'filled'
? {
fill: localProps.color != null ? localProps.color : 'currentColor',
}
: {
stroke: localProps.color != null ? localProps.color : 'currentColor',
'stroke-width':
strokeValue != null ? strokeValue : attributes['stroke-width'],
})}
>
{localProps.title != null && <title>{localProps.title}</title>}
{iconNode.map(([tag, attrs]) => (
<Dynamic component={tag} {...attrs} />
))}
{localProps.children}
</svg>
);
};
Component.displayName = `${iconNamePascal}`;
return Component;
};
export default createSolidComponent;

10
packages/icons-solidjs/test.spec.jsx

@ -62,16 +62,14 @@ describe("Solidjs Icon component", () => {
stroke-linejoin="round"
class="tabler-icon tabler-icon-accessible "
>
<path d="M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0">
<path d="M3 12a9 9 0 1 0 18 0a9 9 0 1 0 -18 0">
</path>
<path d="M10 16.5l2 -3l2 3m-2 -3v-2l3 -1m-6 0l3 1">
</path>
<circle cx="12"
cy="7.5"
r=".5"
fill="currentColor"
<path d="M11.5 7.5a.5 .5 0 1 0 1 0a.5 .5 0 1 0 -1 0"
fill="currentColor"
>
</circle>
</path>
</svg>
`)
})

Loading…
Cancel
Save