Icons: request for svg clock icon
Issue summary
There is no SVG clock icon included with the Shopify Polaris SVG icons
Expected behavior
SVG clock icon being created
Actual behavior
I am currently creating a time input component and would love to have a Polaris svg icon. I am using the calendar svg icon as a prefix on a TextField for the DatePicker and hope to use a similar style clock icon.
Steps to reproduce the problem
- install shopify/polaris
- <Icon source="
- No clock icon available
Specifications
- Polaris version: 1.8.3
- React version: 3.10.10
- Browser: Any
- Device: PC
- Operating System: Windows
⚓️ We’re not accepting pull requests at this time
🗒 This repo is for reporting issues and feature requests only
Thanks @mattchidley. We'll discuss adding this icon to the bundle but in the meantime, just in case you are not aware, you can use your own icon with the icon component:
import clock from './clock.svg';
<Icon source={clock} />
I am not having any luck with the above solution - just keep getting "TypeError: Cannot read property 'viewBox' of undefined." I have checked that the import is successful with <img src={myIcon} /> - am I missing a dependency perhaps?
Hey @alienvir, there is a bit of build configuration required. You need to make sure you are using some sort of bundler for your app that can import SVGs — we use Webpack. For icons, the icon component actually expects a pretty specific structure: an object, that has a viewBox and a body property. You can automatically transform it this way using the @shopify/images/icon-loader for Webpack after installing the @shopify/images NPM package.
If you want to short-circuit all of that, you can simply manually write out your icon in the expected shape:
const icon = {
viewBox: '0 0 20 20',
body: '<path />', // everything in the SVG other than the `<svg>` tag itself
};
<Icon source={icon} />
Thank you. Manually writing the icon structure worked. This is my first experience with react, so I used create-react-app to set up the project and it looks like Webpack is configured automatically. I will need to learn more about manually configuring as I work through this.
We’re working on a better way to distribute icons. For now, using your own icon as described above is what we’d recommend.
Polaris icons are now all available via a new npm package called @shopify/polaris-icons. Find them alongside usage instructions at https://polaris-icons.shopify.com 💟