Skip to content

Commit

Permalink
feat: add src property
Browse files Browse the repository at this point in the history
  • Loading branch information
ju-Skinner committed Jan 5, 2024
1 parent 44e6175 commit 6d46d74
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export namespace Components {
| 'large' // 24px
| 'auto'
| string;
/**
* Specifies the exact `src` of an SVG file to use.
*/
"src"?: string;
}
}
declare global {
Expand Down Expand Up @@ -64,6 +68,10 @@ declare namespace LocalJSX {
| 'large' // 24px
| 'auto'
| string;
/**
* Specifies the exact `src` of an SVG file to use.
*/
"src"?: string;
}
interface IntrinsicElements {
"pds-icon": PdsIcon;
Expand Down
7 changes: 7 additions & 0 deletions src/components/pds-icon/pds-icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ export class PdsIcon {
| 'auto'
| string = 'regular'

/**
*
* Specifies the exact `src` of an SVG file to use.
*/
@Prop() src?: string;

private iconSize() {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const sizes: { [key: string]: any } = {
Expand Down Expand Up @@ -86,6 +92,7 @@ export class PdsIcon {
}

@Watch('name')
@Watch('src')
@Watch('icon')
loadIcon() {
if (Build.isBrowser && this.isVisible) {
Expand Down
1 change: 1 addition & 0 deletions src/components/pds-icon/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
| `icon` | `icon` | This a combination of both `name` and `src`. If a `src` url is detected it will set the `src` property. Otherwise it assumes it's a built-in named SVG and set the `name` property. | `any` | `undefined` |
| `name` | `name` | The name of the icon to use from the built-in set. | `string` | `undefined` |
| `size` | `size` | The size of the icon. This can be 'small', 'regular', 'medium', large, or a custom value (40px, 1rem, etc) | `string` | `'regular'` |
| `src` | `src` | Specifies the exact `src` of an SVG file to use. | `string` | `undefined` |


----------------------------------------------
Expand Down
7 changes: 6 additions & 1 deletion src/components/pds-icon/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ export const getSrc = (src: string | undefined) => {
}

export const getUrl = (pdsIcon: PdsIcon) => {
let url = getName(pdsIcon.name, pdsIcon.icon);
let url = getSrc(pdsIcon.src);
if (url) {
return url;
}

url = getName(pdsIcon.name, pdsIcon.icon);
if (url) {
return getNamedUrl(url);
}
Expand Down

0 comments on commit 6d46d74

Please sign in to comment.