Skip to content

Commit

Permalink
Merge pull request #14 from benflap/dev
Browse files Browse the repository at this point in the history
Add `class` to type declarations
  • Loading branch information
benflap authored Jan 8, 2023
2 parents d9f63ae + cb2a6ec commit 313925a
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 36 deletions.
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"trailingComma": "es5",
"tabWidth": 4,
"semi": true,
"singleQuote": false
"singleQuote": false,
"plugins": ["prettier-plugin-svelte"]
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# tabler-icons-svelte changelog

### 1.9.1

- fix missing type declaration for `class` prop

## 1.9.0

- Support passing down `class` prop ([#10](https://github.com/benflap/tabler-icons-svelte/pull/10))
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ If your build times are high, import the components from their svelte files.

## Props

The components each accept 3 props:

| Prop | Default |
| ----------- | -------------- |
| size | 24 |
| color | `currentColor` |
| strokeWidth | 2 |
| class | `""` |
The components each accept 4 optional props:

| Prop | Default | Description |
| ----------- | -------------- | ---------------------------------------------------------------------------------------- |
| size | 24 | The size of the Icon. Measured in pixels if no other unit is passed. |
| color | `currentColor` | Any valid CSS [\<color\>](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value). |
| strokeWidth | 2 | The SVG's stroke width. Measured in pixels if no other unit is passed. |
| class | `undefined` | Classes that are passed down to the SVG. |

## Development Workflow

Expand Down
39 changes: 30 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tabler-icons-svelte",
"version": "1.9.0",
"version": "1.9.1",
"description": "Tabler Icons as svelte components.",
"license": "MIT",
"author": "Ben Lapp <[email protected]>",
Expand All @@ -13,11 +13,12 @@
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"build": "node ./scripts/generate.cjs"
"build": "node ./scripts/generate.js"
},
"devDependencies": {
"@tabler/icons": "1.84.0",
"prettier": "^2.2.1"
"prettier": "^2.8.2",
"prettier-plugin-svelte": "^2.9.0"
},
"peerDependencies": {
"svelte": ">=3.31.0 <=4"
Expand Down
24 changes: 9 additions & 15 deletions scripts/generate.cjs → scripts/generate.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
const fs = require("fs");
const path = require("path");
const prettier = require("prettier");
import fs from "node:fs";
import path, { dirname } from "node:path";
import prettier, { format } from "prettier";
import { fileURLToPath } from "node:url";

const { format } = prettier;
const __dirname = dirname(fileURLToPath(import.meta.url));

const SOURCE_ICONS_PATH = path.resolve(
__dirname,
"../node_modules/@tabler/icons/icons/"
);
const DIST_PATH = path.resolve(__dirname, "../");
const DESTINATION_ICONS_PATH = path.resolve(__dirname, "../icons");
const TYPES_PATH = path.resolve(DIST_PATH, "types");

const prettierOptions = prettier.resolveConfig(__dirname);

Expand Down Expand Up @@ -62,9 +64,7 @@ function createComponentName(originalName) {
}

function removeOldComponents() {
const components = fs
.readdirSync(DESTINATION_ICONS_PATH)
.filter((file) => file.endsWith(".svelte"));
const components = fs.readdirSync(DESTINATION_ICONS_PATH);
for (const file of components) {
fs.unlinkSync(path.join(DESTINATION_ICONS_PATH, file));
}
Expand Down Expand Up @@ -92,7 +92,7 @@ async function generateNewComponents() {

fs.writeFileSync(
path.resolve(DESTINATION_ICONS_PATH, `${componentName}.svelte`),
format(source, { parser: "html", ...(await prettierOptions) })
format(source, { parser: "svelte", ...(await prettierOptions) })
);
}
}
Expand All @@ -119,13 +119,7 @@ async function createTypesFile() {
const [originalName] = file.split(".");
const componentName = createComponentName(originalName);

return `\
export class ${componentName} extends SvelteComponentTyped<{
color?: string;
size?: string | number;
strokeWidth?: string | number;
}> {}\
`;
return `export class ${componentName} extends TablerIcon {}`;
});

fs.writeFileSync(
Expand Down
9 changes: 9 additions & 0 deletions scripts/types-template.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
import { SvelteComponentTyped } from "svelte";

type TablerIconProps = {
color?: string;
size?: string | number;
strokeWidth?: string | number;
class?: string;
};

class TablerIcon extends SvelteComponentTyped<TablerIconProps> {}

0 comments on commit 313925a

Please sign in to comment.