Skip to content

Commit

Permalink
fix: some icons issues (#435)
Browse files Browse the repository at this point in the history
* fix: use proper prefixing for icons defs ids

* fix: avoid showing the passed classes twice

* add changeset
  • Loading branch information
elevatebart committed May 2, 2024
1 parent 6b9363d commit bf0ef3f
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .changeset/icon-double-class-vue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@cypress-design/react-icon": patch
"@cypress-design/vue-icon": patch
"@cypress-design/icon-registry": patch
---

fix: avoid showing the passed classes twice
7 changes: 7 additions & 0 deletions .changeset/icon-prefix-ids.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@cypress-design/react-icon": patch
"@cypress-design/vue-icon": patch
"@cypress-design/icon-registry": patch
---

fix: use proper prefixing for icons defs ids
6 changes: 6 additions & 0 deletions components/Icon/react/IconReact.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,10 @@ describe('Icon', { viewportWidth: 80, viewportHeight: 80 }, () => {

cy.get('svg title').should('have.text', 'This is a <b>title</b>')
})

it('renders class passed only once', () => {
mount(<IconBrowserWebkit className="w-16 h-16" />)

cy.get('svg[width="16"]').should('have.attr', 'class', 'w-16 h-16')
})
})
8 changes: 7 additions & 1 deletion components/Icon/vue/IconVue.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Icon', { viewportWidth: 80, viewportHeight: 80 }, () => {
if (props.name) {
return mount(() => <Icon {...props} />)
}
mount(() => <IconDocumentBlank {...props} />)
mount(() => <IconDocumentBlank {...props} class={props.class} />)
})

it('renders correctly with array classes', () => {
Expand Down Expand Up @@ -128,4 +128,10 @@ describe('Icon', { viewportWidth: 80, viewportHeight: 80 }, () => {

cy.get('svg title').should('have.text', 'This is a title')
})

it('renders class passed only once', () => {
mount(() => <IconBrowserWebkit class="w-16 h-16" />)

cy.get('svg[width="16"]').should('have.attr', 'class', 'w-16 h-16')
})
})
2 changes: 1 addition & 1 deletion components/Icon/vue/generate-icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const __iconComponentOpts__ = {
function useIconProps(props: SVGAttributes & Omit<iconsRegistry.IconProps, 'name'>, iconBodiesAndDefs: Record<string, {body: string, defs?: string}>, availableSizes: string[], name: string) {
return computed(() => {
const { interactiveColorsOnGroup, ...cleanProps } = props
const { interactiveColorsOnGroup, class:_, ...cleanProps } = props
const { sizeWithDefault: size, compiledClasses } = iconsRegistry.getComponentAttributes({
...cleanProps,
Expand Down
5 changes: 4 additions & 1 deletion icon-registry/generate-icons-content.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ export default async function getIcons() {
const [kebabCaseName, size] = iconName.split('_x')
const svgContent = optimize(
await fs.readFile(path.join(cwd, icon), 'utf8'),
config ?? undefined,
{
path: path.join(cwd, icon),
...config,
},
).data

const iconMetaWithSize = {
Expand Down
1 change: 1 addition & 0 deletions icon-registry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@types/lodash-es": "^4.17.12",
"dedent": "^1.5.1",
"globby": "^14.0.1",
"hash-sum": "^2.0.0",
"lodash-es": "^4.17.21",
"xml2js": "^0.6.2"
}
Expand Down
5 changes: 5 additions & 0 deletions icon-registry/svgo.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const hashSum = require('hash-sum')
const extractBodyPlugin = require('./svgo-plugins/extractBodyPlugin')
const moveDefsToEndPlugin = require('./svgo-plugins/moveDefsToEnd')

Expand All @@ -10,6 +11,10 @@ module.exports = {
name: 'prefixIds',
params: {
prefixClassNames: false,
delim: '',
prefix: (el, ctx) => {
return `cy-svg-${hashSum(ctx.path)}`
},
},
},
moveDefsToEndPlugin,
Expand Down
12 changes: 12 additions & 0 deletions test/vue-app/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import Accordion from '@cypress-design/vue-accordion'
import Checkbox from '@cypress-design/vue-checkbox'
import Icon, {
IconActionQuestionMarkCircle,
IconBrowserChrome,
IconBrowserEdge,
IconBrowserMozillaFirefox,
IconBrowserSafari,
IconBrowserWebkit,
IconObjectBookCode,
IconObjectMagnifyingGlass,
} from '@cypress-design/vue-icon'
Expand All @@ -19,6 +24,13 @@ const showModal = ref(false)
</script>

<template>
<div class="my-40 mx-auto justify-center flex gap-4">
<IconBrowserChrome class="h-32 w-32" />
<IconBrowserSafari class="h-32 w-32" />
<IconBrowserMozillaFirefox class="h-32 w-32" />
<IconBrowserWebkit class="h-32 w-32" />
<IconBrowserEdge class="h-32 w-32" />
</div>
<div
class="@container/main mb-4 overflow-hidden max-w-[600px] mx-auto text-center"
>
Expand Down

0 comments on commit bf0ef3f

Please sign in to comment.