-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into ao-openai-icon
- Loading branch information
Showing
162 changed files
with
4,340 additions
and
1,842 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { transform } from '@babel/core'; | ||
|
||
import plugin from '../mask-plugin'; | ||
|
||
const maskIdString = '`${maskId}`'; | ||
const urlIdString = '`url(#${maskId})`'; | ||
const size = '`100%`'; | ||
const currentColor = '`currentColor`'; | ||
|
||
const menuIcon = | ||
"<svg viewBox='0 0 16 16' height='16' width='16'><title>mini-bold-interface-arrow-up</title><g transform='matrix(1.6,0,0,1.6,0,0)'><path d='M8.03,2.72,5.53.22a.749.749,0,0,0-1.06,0l-2.5,2.5A.75.75,0,0,0,3.03,3.78L4.25,2.561V9.25a.75.75,0,0,0,1.5,0V2.561L6.97,3.78A.75.75,0,1,0,8.03,2.72Z' fill='#000000' stroke='none' stroke-linecap='round' stroke-linejoin='round' stroke-width='0'></path></g></svg>"; | ||
|
||
const menuIconTitleEnd = | ||
"<svg viewBox='0 0 16 16' height='16' width='16'><g transform='matrix(1.6,0,0,1.6,0,0)'><path d='M8.03,2.72,5.53.22a.749.749,0,0,0-1.06,0l-2.5,2.5A.75.75,0,0,0,3.03,3.78L4.25,2.561V9.25a.75.75,0,0,0,1.5,0V2.561L6.97,3.78A.75.75,0,1,0,8.03,2.72Z' fill='#000000' stroke='none' stroke-linecap='round' stroke-linejoin='round' stroke-width='0'></path></g><title>mini-bold-interface-arrow-up</title></svg>"; | ||
|
||
const postTransformIcon = `"<svg viewBox='0 0 16 16' height='16' width='16'><title>mini-bold-interface-arrow-up</title><mask id={${maskIdString}}><g transform='matrix(1.6,0,0,1.6,0,0)'><path d='M8.03,2.72,5.53.22a.749.749,0,0,0-1.06,0l-2.5,2.5A.75.75,0,0,0,3.03,3.78L4.25,2.561V9.25a.75.75,0,0,0,1.5,0V2.561L6.97,3.78A.75.75,0,1,0,8.03,2.72Z' fill='#000000' stroke='none' stroke-linecap='round' stroke-linejoin='round' stroke-width='0'></path></g></mask><g mask={${urlIdString}}><rect width={${size}} height={${size}} fill={${currentColor}} /></g></svg>;"`; | ||
|
||
const testPlugin = (code: string) => { | ||
const result = transform(code, { | ||
plugins: ['@babel/plugin-syntax-jsx', plugin], | ||
configFile: false, | ||
}); | ||
|
||
return result?.code; | ||
}; | ||
|
||
describe('title plugin', () => { | ||
it('should add a mask wrapper, add a mask id, and applies currentColor to the rect tag', () => { | ||
expect(testPlugin(menuIcon)).toMatchInlineSnapshot(postTransformIcon); | ||
}); | ||
it('sets title outside of mask regardless of placement', () => { | ||
expect(testPlugin(menuIconTitleEnd)).toMatchInlineSnapshot( | ||
postTransformIcon | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
const plugin = (api) => { | ||
const { types } = api; | ||
|
||
const maskTag = types.jSXIdentifier('mask'); | ||
const gTag = types.jSXIdentifier('g'); | ||
const rectTag = types.jSXIdentifier('rect'); | ||
|
||
const createUniqueAttributeId = (tag) => { | ||
const titleId = '${maskId}'; | ||
const newId = tag === 'mask' ? `url(#${titleId})` : titleId; | ||
return newId; | ||
}; | ||
|
||
const createAttribute = (tag, value) => { | ||
const backtick = '`'; | ||
return types.jsxAttribute( | ||
types.jsxIdentifier(tag), | ||
types.jsxExpressionContainer( | ||
types.identifier(`${backtick}${value}${backtick}`) | ||
) | ||
); | ||
}; | ||
|
||
const vistor = { | ||
JSXElement(path) { | ||
if (!path.get('openingElement.name').isJSXIdentifier({ name: 'svg' })) { | ||
return; | ||
} | ||
let titleNode; | ||
|
||
path.get('children').some((childPath) => { | ||
// we want to delete the title and reinsert it so it lands outside the mask. this fixes some issues with svgr's built-in titleProp parsing. | ||
if (!childPath.isJSXElement()) return false; | ||
const name = childPath.get('openingElement').get('name'); | ||
if (name.node.name === 'title') { | ||
titleNode = childPath.node; | ||
childPath.remove(); | ||
} | ||
return false; | ||
}); | ||
|
||
const newId = createAttribute('id', createUniqueAttributeId('id')); | ||
|
||
const ogOpen = path.get('openingElement').node; | ||
const ogClose = path.get('closingElement').node; | ||
|
||
const maskTagOpen = types.jsxOpeningElement(maskTag, [newId]); | ||
const maskTagClosed = types.jsxClosingElement(maskTag, []); | ||
|
||
const maskGAttr = createAttribute( | ||
'mask', | ||
createUniqueAttributeId('mask') | ||
); | ||
|
||
const gTagOpen = types.jsxOpeningElement(gTag, [maskGAttr]); | ||
|
||
const gTagClose = types.jsxClosingElement(gTag, []); | ||
|
||
const rectTagComplete = types.jsxElement( | ||
types.jsxOpeningElement( | ||
rectTag, | ||
[ | ||
createAttribute('width', '100%'), | ||
createAttribute('height', '100%'), | ||
createAttribute('fill', 'currentColor'), | ||
], | ||
true | ||
), | ||
null, | ||
[], | ||
true | ||
); | ||
|
||
const newerChildren = types.jsxElement(gTagOpen, gTagClose, [ | ||
rectTagComplete, | ||
]); | ||
const newChildren = types.jsxElement(maskTagOpen, maskTagClosed, [ | ||
...path.node.children, | ||
]); | ||
|
||
path.replaceWith( | ||
types.jsxElement(ogOpen, ogClose, [newChildren, newerChildren]) | ||
); | ||
|
||
path.node.children.unshift(titleNode); | ||
path.skip(); | ||
}, | ||
}; | ||
|
||
return { | ||
visitor: { | ||
Program(path) { | ||
path.traverse(vistor); | ||
}, | ||
}, | ||
}; | ||
}; | ||
|
||
module.exports = plugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
packages/gamut-icons/src/svg/regular/arrow-thick-circle-up-icon.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.