Skip to content

Commit

Permalink
feat: react support export svgNames/type SvgName
Browse files Browse the repository at this point in the history
  • Loading branch information
Jevon617 committed Apr 24, 2023
1 parent 37a4e44 commit 8d80628
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ function App() {
}
```

### Get `svgNames` / type `SvgName`

```ts
// all svg icon name
import { svgNames } from '~virtual/svg-component'

// type SvgName = "icon-icon-addUser" | "icon-icon-barCode"
import type { SvgName } from '~virtual/svg-component'
```

## Plugin Configuration

| Parameter | Type | Default | Description |
Expand Down
9 changes: 9 additions & 0 deletions README.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ function App() {
}
```

### 获取`svgNames` / 类型 `SvgName`
```ts
// all svg icon name
import { svgNames } from '~virtual/svg-component'

// type SvgName = "icon-icon-addUser" | "icon-icon-barCode"
import type { SvgName } from '~virtual/svg-component'
```

## 插件配置

| 属性 | 类型 | 默认值 | 描述 |
Expand Down
9 changes: 8 additions & 1 deletion examples/react-vite/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import './App.css'
import MySvgIcon from '~virtual/svg-component'
import type { SvgName } from '~virtual/svg-component'

import MySvgIcon, { svgNames } from '~virtual/svg-component'

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const test: SvgName = 'icon-react'

// eslint-disable-next-line no-console
console.log(svgNames)
function App() {
return (
<div className="logo">
Expand Down
2 changes: 2 additions & 0 deletions examples/react-vite/src/typing/svg-component.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

declare module '~virtual/svg-component' {
const MySvgIcon: ({name}: {name: "icon-icon-addUser" | "icon-icon-barCode" | "icon-icon-card2" | "icon-react"})=> JSX.Element;
export const svgNames: ["icon-icon-addUser" , "icon-icon-barCode" , "icon-icon-card2" , "icon-react"];
export type SvgName = "icon-icon-addUser" | "icon-icon-barCode" | "icon-icon-card2" | "icon-react";
export default MySvgIcon;
}
2 changes: 2 additions & 0 deletions src/core/snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export default function $component_name({name}) {
export const reactDts = `
declare module '${MODULE_NAME}' {
const $component_name: ({name}: {name: "$svg_symbolIds"})=> JSX.Element;
export const svgNames: ["$svg_names"];
export type SvgName = "$svg_symbolIds";
export default $component_name;
}
`

0 comments on commit 8d80628

Please sign in to comment.