-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(fw-icon-library): fwIcon extensions and IconLibrary #340
Conversation
…le Imports, Icon Lib & Mutator
}; | ||
|
||
// Icon fetch-api with memoization : fw-icon | ||
const CRAYONS_ICONS_ASSET_PATH = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At present we are deploying to canary
tag. The above url will not work with the current release setup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
<code-group> | ||
<code-block title="HTML"> | ||
```html | ||
<fw-icon data-svg={ header } size="20" ></fw-icon> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls add the code to import header
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
fw-icon can also render external icons. You can use any external libraries from cdn after registering them. If you don't pass 'library' props, | ||
it will default to 'crayons'. You can even pass the CDN URL of SVG to 'src' prop. See the example below on how to use in React App. | ||
|
||
The library registration happpens via a 'ressolver' function. If you wish to apply some mutation to the icons , you may also choose to pass the mutator function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls fix the typo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
|
||
### Usage in HTML/React Page | ||
<code-group> | ||
<code-block title="HTML-FwIconLibrary"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can keep the title as just HTML
and React
to stay consistent with other components.
If you want to add variations, pls mention as comments in the code section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
|
||
1. Enable fw-icon as an optimized renderer for SVG with built-in functions such as Intersection-Observer and Fetch-API Memoization. | ||
Go through the docs to understand the various props it supports. | ||
2. React-Support as part of Crayons Release. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove this statement, since by default we provide React
wrapper for all the components.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
|
||
Crayons Icon is now available as '@freshworks/crayons-icon' Library. This encapsulates all Icon Tooling icon exports. Following is implemented via the Lib. | ||
|
||
1. JS Exports of SVG Icon to enable Tree-Shaking for inline-svg. This is a useful feature where Dev Team can choose to do something offline with SVGs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of addressing as Dev
or development
team , you can just address as you
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not resolved still. Can you please check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
|
||
function App() { | ||
return (<div> | ||
<FwIcon data-svg={ header } size="20" ></FwIcon> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would break in a typescript app . Please pass the correct type as value for the props.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
} | ||
} catch (ex) { | ||
console.info( | ||
`Cannot load ${name}|${library} from CDN. Please check the url & proide a live path.`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls fix the typo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
|
||
1. JS Exports of SVG Icon to enable Tree-Shaking for inline-svg. This is a useful feature where Dev Team can choose to do something offline with SVGs. | ||
2. Enable Crayons-Icon lib to support external icon libraries. The development team can register external icon libraries via register API. See usage docs. | ||
3. Optimized SVGs using SVGO via .yml configuration. The development team can extend the .yml file and use it in their app for optimizing their custom icons. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you provide an example for this ?. How can a consuming app extend and optimize their custom svgs?.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will need to address after PR Merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added CLI Showcase
'--icon-color': this.color, | ||
}; | ||
async loadFallbackImage() { | ||
this.svgHTML = await fetchIcon('image', 'crayons', undefined); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can avoid passing the 3rd argument instead of passing it as undefined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
…m icons ,refactored getSVGState fw-icon
@@ -36,11 +36,11 @@ import { Meta, Story, Preview, Props } from '@storybook/addon-docs/blocks'; | |||
<fw-icon | |||
name='minus' | |||
size="14" | |||
slot="expanded-icon"></fw-icon> | |||
slot="expanded-icon" library="system" ></fw-icon> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cant you set it up so that if library is not mentioned , it defaults to using our default icon library ? Basically in your code you set library prop default value to "system" else all components have to be changed as in this PR which has resulted in 57 changed files!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not seem possible as we provide crayons icons as the default set. System icon is a subset but we cannot set it to default. Also, there is no way we can make out if it's used from an internal component or an external component. In Shoelace also they are passing library='system' in all internal components.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested all those components and its working. I tested by making it fail, then enabling the system mode. We can also do some quick sanity testing by individual developers who worked on that component. They can pull this branch and test it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments I have added! please check!
but mostly looks good!
// icons are a subset of Crayons Icons. | ||
// | ||
const crayons_system_icons = { | ||
'add-contact': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@detiwari003 Shall we restrict this list to have what is used within the crayons component and move out other icons like add-contact!
The ones used inside the readme can point to crayons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
'vertical-align-top': | ||
"<svg viewBox='0 0 16 16'><path d='M15.3.1H.7a.7.7 0 1 0 0 1.4H2v13.7a.7.7 0 0 0 .7.7h3.6a.7.7 0 0 0 .7-.7V1.5h2v5.7a.7.7 0 0 0 .7.7h3.6a.7.7 0 0 0 .7-.7V1.5h1.3a.7.7 0 0 0 0-1.4zM5.6 14.5H3.4v-13h2.2v13zm7-8h-2.2v-5h2.2v5z' fill='currentColor' fill-rule='evenodd'/></svg>", | ||
'warning': | ||
"<svg viewBox='0 0 16 16'><path d='M8 0a8 8 0 1 1-8 8 8 8 0 0 1 8-8zm0 1.4A6.6 6.6 0 1 0 14.6 8 6.6 6.6 0 0 0 8 1.4zm.05 8.66a1 1 0 0 1 1.05 1.05 1.05 1.05 0 1 1-1.05-1.05zm.35-5.966a.7.7 0 0 1 .35.606v3.61a.7.7 0 0 1-1.4 0V4.7a.7.7 0 0 1 1.05-.606z' fill='#e43538'/></svg>", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not theme at the base level. I understand that this was originally done in the icon, but lets change it.
fill='#e43538' => fill='currentColor'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
export { ToastController, ProgressLoaderController, fwIconRegisterLibrary, fwIconUnregisterLibrary } from '../dist/components/index' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets rename
fwIconUnregisterLibrary
-> registerLibrary
fwIconUnregisterLibrary
-> unregisterLibrary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
name='plus' | ||
size="14" | ||
slot="collapsed-icon"></fw-icon> | ||
slot="collapsed-icon" system library="system" ></fw-icon> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can u remove the attribute system
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohh.ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
if (hasLabel) { | ||
accessibilityProps['role'] = 'img'; | ||
accessibilityProps['aria-label'] = this.label; | ||
accessibilityProps['aria-hidden'] = undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to explicity set the value as undefined
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set to true. Fixed
1. Enable fw-icon as an optimized renderer for SVG with built-in functions such as Intersection-Observer and Fetch-API Memoization. | ||
Go through the docs to understand the various props it supports. | ||
2. Providing icon-support for crayons-system components and also exposing crayons-icon set for public use with inbuilt support for external icon-libraries also. | ||
3. Icons are accessibility tree compliant. You need to pass the label attribute. aria-hidden is set to true. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have set aria-hidden
to undefined
above. Here it is mentioned it as being set to true
. Can you pls check .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
@@ -23,28 +30,188 @@ import ReactDOM from "react-dom"; | |||
import { FwIcon } from "@freshworks/crayons/react"; | |||
function App() { | |||
return (<div> | |||
<FwIcon name="add-contact" size="18" color="green"></FwIcon> | |||
<FwIcon name="add-contact" size="18" color="green" ></FwIcon> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will result in typeerror in a Typescript app. Can you please correct it ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
### Icons | ||
### Intersection Observer | ||
|
||
Use prop 'lazy' to enable Intersection-Observer. By deafult it is disabled. You may choose to give the intersection root-margin for icons i.e via prop 'x-root-margin' as preloading threshold in a viewport.Default value is '50px'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix the typo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
throw 'Icon-URL Not Valid.'; | ||
} | ||
} catch (ex) { | ||
console.info( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are throwing an error with a message but in the below catch block , you are not logging that error but instead just having a static error description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Thanks Parsu. I have now closed all review comments and tested them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There is one minor comment that you need to address.
www/css-utils/card/readme.md
Outdated
@@ -21,7 +21,7 @@ To apply card css utils, we can use 'fw-card-#{$elevation}' | |||
</div> | |||
<div class="fw-flex-grow-0"> | |||
<fw-button size="icon" color="text" role="button" class="fw-ml-12"> | |||
<fw-icon name="delete"></fw-icon> | |||
<fw-icon name="delete" library="system" ></fw-icon> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete and inbox will be part of the crayons library, right? let's change this otherwise, the documentation will be wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
if (hasLabel) { | ||
accessibilityProps['role'] = 'img'; | ||
accessibilityProps['aria-label'] = this.label; | ||
accessibilityProps['aria-hidden'] = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we not set the aria-hidden to true
by default for icons. Here if the label is not passed, aria-hidden attribute will not be set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
package.json
Outdated
@@ -74,6 +74,7 @@ | |||
"stylelint-prettier": "^1.2.0", | |||
"stylelint-scss": "^3.21.0", | |||
"vuepress": "^1.8.2", | |||
"vuepress-plugin-demo-code": "^0.6.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@detiwari003 Is this dependency required ?. Where is it being used in the docs site ?. Can you please check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM except for the couple of items regarding a11y and a new dependency being added. kindly check on them.
…le Imports, Icon Lib & Mutator
Checklist:
How Has This Been Tested?