Skip to content

Commit

Permalink
feat(@clayui.com): icon filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
kresimir-coko committed Feb 17, 2020
1 parent d8db899 commit cfec748
Show file tree
Hide file tree
Showing 6 changed files with 2,435 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ title: 'Icons'
description: 'Icons are a visual representation of an idea and/or action.'
---

import IconSearch from '../../../src/components/IconSearch';
import icons from '../../../static/js/icons.json';
import flags from '../../../static/js/flags.json';

<div class="nav-toc-absolute">
<div class="nav-toc">

- [Usage](#usage)
- [Icon List](#icon-list)
- [Language Flags](#language-flags)
- [SVG Icons as Background Images](#svg-icons-as-background-images)
- [Clay-SVG-url()](<#clay-svg-url()>)
Expand All @@ -16,11 +21,22 @@ description: 'Icons are a visual representation of an idea and/or action.'
</div>

<div class="clay-site-alert alert alert-info">
Check the <a href="https://liferay.design/lexicon">Lexicon</a> <a href="https://liferay.design/lexicon/core-components/icons/">Icons Pattern</a> for a more in-depth look at the motivations and proper usage of this component.
Check the <a href="https://liferay.design/lexicon">Lexicon</a>{' '}
<a href="https://liferay.design/lexicon/core-components/icons/">
Icons Pattern
</a>{' '}
for a more in-depth look at the motivations and proper usage of this
component.
</div>

<div class="clay-site-alert alert alert-warning">
See the implementation of the <a href="/docs/components/icons.html">Icons component in React</a> following the Lexicon <a href="https://liferay.design/lexicon/core-components/icons/">Icons Pattern</a>.
See the implementation of the{' '}
<a href="/docs/components/icons.html">Icons component in React</a> following
the Lexicon{' '}
<a href="https://liferay.design/lexicon/core-components/icons/">
Icons Pattern
</a>
.
</div>

## Usage
Expand All @@ -39,9 +55,9 @@ We use SVG elements that link to an SVG sprite, like so:

Note that the ID after the # symbol is the ID of the icon to use, so if you wanted to use plus icon, you would do change the href to `path/to/icons.svg#plus`.

<ul class="lexicon-icon-list list-unstyled">
[foreach Icons]
</ul>
## Icon List

<IconSearch source={icons} />

## Language Flags

Expand All @@ -53,9 +69,12 @@ Or, to paraphrase Winston Churchill, "Using flags is the worst system for indica

To use the flags below, follow the same process as you would for a standard icon, and use the locale and country code indicated in parenthesis for the icon's name (e.g. to use the Japanese icon, you would use `ja-jp`)

<ul class="lexicon-icon-list list-unstyled">
[foreach Flags]
</ul>
<IconSearch
label="Search Flags"
placeholder="Search Flags..."
source={flags}
type="flags"
/>

### SVG Icons as Background Images

Expand All @@ -75,17 +94,20 @@ We have created a Sass function to turn Lexicon SVG icon's into data uri schemes
You can turn your custom SVG into a data uri using the Sass function `clay-svg-url($svg)`, where `$svg` is the code for your inline SVG. The function returns `url(your_svg_as_data_uri)`.

<div class="alert alert-info">
When using `clay-svg-url()`, wrap your inline SVG code with single quotes if your SVG's attributes are delimited with double quotes.
When using `clay-svg-url()`, wrap your inline SVG code with single quotes if
your SVG's attributes are delimited with double quotes.
</div>

<span class="clay-site-linux-tux clay-site-svg-bg">Linux Tux</span>

## Why do we use SVG

<p id="lexicon-icon-explanation">
Font icons, while fairly simple, suffer drawbacks, such as sub-pixel aliasing. This results in a lower quality than we would like.
SVG gives us and you a greater amount of freedom in styling the icons, as well as a higher level of fidelity and clarity in the icons.
Also, SVG supports multi-color icons, as shown below:
Font icons, while fairly simple, suffer drawbacks, such as sub-pixel
aliasing. This results in a lower quality than we would like. SVG gives us
and you a greater amount of freedom in styling the icons, as well as a
higher level of fidelity and clarity in the icons. Also, SVG supports
multi-color icons, as shown below:
</p>

<div class="lexicon-icon-examples">
Expand Down
4 changes: 4 additions & 0 deletions clayui.com/content/docs/components/icon.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ sibling: 'docs/components/css-icons.html'
---

import {Icon, IconWithContext} from '../../../src/components/clay/Icon';
import IconSearch from '../../../src/components/IconSearch';
import icons from '../../../static/js/icons.json';

<div class="nav-toc-absolute">
<div class="nav-toc">
Expand All @@ -17,6 +19,8 @@ import {Icon, IconWithContext} from '../../../src/components/clay/Icon';
</div>
</div>

<IconSearch source={icons} />

<div class="clay-site-alert alert alert-warning">
Take a look at our{' '}
<a href="https://storybook-clayui.netlify.com/?path=/story/clayicon--default">
Expand Down
84 changes: 84 additions & 0 deletions clayui.com/src/components/IconSearch/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* © 2020 Liferay, Inc. <https://liferay.com>
*
* SPDX-License-Identifier: BSD-3-Clause
*/

import ClayForm, {ClayInput} from '@clayui/form';
import ClayIcon from '@clayui/icon';
import React, {useMemo, useState} from 'react';

const spritemap = '/images/icons/icons.svg';

/**
* Component that allows searching through icons
* @param {string} label - Label of the search input field.
* @param {string} placeholder - Placeholder of the search input field.
* @param {Array[Object]} source - Path to the source JSON. Needs to follow pattern of [{name: String, aliases: Array<String>}]
* @param {string} type - Type of icons being provided, supports "icons" and "flags"
*/
const IconSearch = ({
label = 'Search Icons',
placeholder = 'Search Icons...',
source,
type = 'icons',
}) => {
const [searchQuery, setSearchQuery] = useState('');
let list = [];

const filteredIcons = useMemo(() => {
const query = searchQuery.toLowerCase();

return source.filter(
({aliases, name}) =>
name.toLowerCase().includes(query) ||
aliases.some(alias => alias.toLowerCase().includes(query))
);
}, [searchQuery]);

if (filteredIcons.length) {
list = filteredIcons;
} else {
list = searchQuery ? [] : source;
}

return (
<>
<ClayForm.Group>
<label style={{width: '100%'}}>
{label}

<ClayInput
onChange={event => setSearchQuery(event.target.value)}
placeholder={placeholder}
type="text"
value={searchQuery}
/>
</label>

<ul className="lexicon-icon-list list-unstyled">
{list.map(icon => (
<li key={icon.name}>
<ClayIcon
spritemap={spritemap}
symbol={icon.name}
/>

<span>
{type === 'flags'
? icon.aliases.join(' - ')
: icon.name}
</span>
</li>
))}
</ul>

{!list.length && (
<span>{`No results found for ${searchQuery}`}</span>
)}
</ClayForm.Group>
</>
);
};

export default IconSearch;
85 changes: 64 additions & 21 deletions clayui.com/src/templates/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@ export default props => {
location,
pageContext: {blacklist = [], markdownJsx},
} = props;
const {allMarkdownRemark, allMdx, markdownRemark, mdx, tabs} = data;
const {
allMarkdownRemark,
allMdx,
markdownRemark,
mdTab,
mdx,
mdxTab,
} = data;
const {code, excerpt, fields, frontmatter, html, timeToRead} =
mdx || markdownRemark;

const hasTabs = tabs.edges.length > 0;
const tab = mdTab || mdxTab;

const title = `${frontmatter.title} - Clay`;

Expand Down Expand Up @@ -99,13 +106,8 @@ export default props => {
</p>
)}
</div>
{!hasTabs && (
<div className="col-12">
<hr className="clay-site-separator" />
</div>
)}
{hasTabs && (
<div className="col-12">
<div className="col-12">
{tab ? (
<ul
className="border-bottom nav nav-clay nav-underline"
role="tablist"
Expand Down Expand Up @@ -138,8 +140,10 @@ export default props => {
</a>
</li>
</ul>
</div>
)}
) : (
<hr className="clay-site-separator" />
)}
</div>
</div>
</div>
</header>
Expand Down Expand Up @@ -250,17 +254,55 @@ export default props => {
}
</p>
)}
{hasTabs && (
{tab.html && (
<div
dangerouslySetInnerHTML={{
__html:
tabs
.edges[0]
.node
.html,
mdTab.html,
}}
/>
)}
{tab.code && (
<article>
<CodeClipboard>
<MDXProvider
components={{
h1:
Typography.H1,
h2:
Typography.H2,
h3:
Typography.H3,
h4:
Typography.H4,
p:
Typography.P,
ul: props => (
<ul
className={
props.className
? props.className
: 'clay-ul'
}
>
{
props.children
}
</ul>
),
}}
>
<MDXRenderer>
{
mdxTab
.code
.body
}
</MDXRenderer>
</MDXProvider>
</CodeClipboard>
</article>
)}
</div>
</div>
</div>
Expand Down Expand Up @@ -369,11 +411,12 @@ export const pageQuery = graphql`
}
}
}
tabs: allMarkdownRemark(filter: {fields: {slug: {eq: $sibling}}}) {
edges {
node {
html
}
mdTab: markdownRemark(fields: {slug: {eq: $sibling}}) {
html
}
mdxTab: mdx(fields: {slug: {eq: $sibling}}) {
code {
body
}
}
}
Expand Down
Loading

0 comments on commit cfec748

Please sign in to comment.