Skip to content
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

Merged
merged 14 commits into from
Dec 17, 2021

Conversation

detiwari003
Copy link
Contributor

@detiwari003 detiwari003 commented Dec 13, 2021

…le Imports, Icon Lib & Mutator

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • My commits have standard messages as mentioned in Contributing Guidelines

How Has This Been Tested?

};

// Icon fetch-api with memoization : fw-icon
const CRAYONS_ICONS_ASSET_PATH =
Copy link
Collaborator

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.

Copy link
Contributor Author

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>
Copy link
Collaborator

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

Copy link
Contributor Author

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls fix the typo

Copy link
Contributor Author

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">
Copy link
Collaborator

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.

Copy link
Contributor Author

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.
Copy link
Collaborator

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.

Copy link
Contributor Author

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.
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Collaborator

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

Copy link
Contributor Author

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>
Copy link
Collaborator

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.

Copy link
Contributor Author

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.`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls fix the typo

Copy link
Contributor Author

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.
Copy link
Collaborator

@arvindanta arvindanta Dec 13, 2021

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?.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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);
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -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>
Copy link
Contributor

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!

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@parsuram-vijaysankar parsuram-vijaysankar left a 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':
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to 10 files. These are those central components which are indispensable.

Screenshot 2021-12-15 at 10 41 07 PM

Copy link
Contributor Author

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>",
Copy link
Contributor

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'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Contributor Author

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'
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Contributor Author

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>
Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohh.ok

Copy link
Contributor Author

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;
Copy link
Collaborator

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?

Copy link
Contributor Author

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.
Copy link
Collaborator

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 .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Contributor Author

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>
Copy link
Collaborator

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 ?

Copy link
Contributor Author

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'.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the typo

Copy link
Contributor Author

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(
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@detiwari003 detiwari003 self-assigned this Dec 16, 2021
@detiwari003
Copy link
Contributor Author

Minor comments I have added! please check! but mostly looks good!

Thanks Parsu. I have now closed all review comments and tested them.

@detiwari003 detiwari003 reopened this Dec 16, 2021
Copy link
Contributor

@parsuram-vijaysankar parsuram-vijaysankar left a 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.

@@ -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>
Copy link
Contributor

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.

Copy link
Contributor Author

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;
Copy link
Collaborator

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.

Copy link
Contributor Author

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",
Copy link
Collaborator

@arvindanta arvindanta Dec 16, 2021

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Collaborator

@arvindanta arvindanta left a 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.

@detiwari003 detiwari003 merged commit 9e5ceb3 into canary Dec 17, 2021
@detiwari003 detiwari003 deleted the fw-icon-library branch December 17, 2021 06:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants