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

adjust icon sizing, add icon-wrapper class, closes #763 #781

Merged
merged 2 commits into from
May 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions site/catalog/icons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import React from 'react';
import fs from 'fs';
import path from 'path';

const icons = fs.readdirSync(path.join(__dirname, '../../src/svgs'))
.filter((filename) => filename.endsWith('.svg'))
.map((filename) => path.basename(filename, '.svg'));

const fontSizes = [
'txt-h1',
'txt-h2',
'txt-h3',
'txt-xl',
'txt-l',
'txt-m',
'txt-s',
'txt-xs'
];

const iconSizes = [
'icon',
'icon icon--s',
'icon icon--l',
];

const wrapperClass = 'icon-inliner';

const getIconEl = (icon) => {
return (
<div key={icon} className='relative mb24 pb12 border-b border--gray-faint'>

<div className='mb12'>
<button className='btn round-full'>
<div className={wrapperClass}>
<svg className='icon'>
<use xlinkHref={`#icon-${icon}`} />
</svg>
</div>
Button label
</button>
</div>

{fontSizes.map((f) => iconSizes.map((c) => <div className={`mb12 ${f}`}>
<div className={f.includes('h') ? wrapperClass + ' icon-inliner--heading' : wrapperClass}>
<svg className={c}>
<use xlinkHref={`#icon-${icon}`} />
</svg>
</div>
<span>Curabitur blandit tempus porttitor.</span>
<div className={f.includes('h') ? wrapperClass + ' icon-inliner--heading' : wrapperClass}>
<svg className={c}>
<use xlinkHref={`#icon-${icon}`} />
</svg>
</div>
</div>))}
</div>
);

};

class Icons extends React.Component {
render() {
// Get a random icon from all icons. Because why not.
const iconEls = getIconEl(icons[Math.floor(Math.random() * icons.length)]);

return (
<div>
<h2 className='border-b border--2 border--gray-faint pb6 mt72 mb24 txt-l txt-bold'>
Icons
</h2>

{iconEls}

</div>
);
}
}

export { Icons };
7 changes: 6 additions & 1 deletion site/catalog/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ import { Textareas } from './textareas';
import { Ranges } from './ranges';
import { Links } from './links';
import { Grids } from './grids';
import { Icons } from './icons';
import { Flexbox } from './flexbox';

class Catalog extends React.Component {
render() {
return (
<div className='pt24 '>
<div className='pt24'>

<h1 className='txt-h2 txt-bold mb18'>Catalog</h1>
<p className='col col--6-mm'>A catalog of Assembly variations for reference and debugging purposes.</p>
<div id='Typography' className='mb48'>
Expand Down Expand Up @@ -75,6 +77,9 @@ class Catalog extends React.Component {
<div id='Radios' className='mb48'>
<Radios />
</div>
<div id='Icons' className='mb48'>
<Icons />
</div>
<div id='Triangles' className='mb48'>
<Triangles />
</div>
Expand Down
2 changes: 1 addition & 1 deletion site/documentation/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class Entry extends React.Component {
target='_blank'
className='txt-s link inline-block link--gray'
>
<svg className='align-t inline-block mr6 icon'><use xlinkHref='#icon-code'/></svg>
<svg className='align-t inline-block mr6 mt3 icon icon--s'><use xlinkHref='#icon-code'/></svg>
{path.basename(props.parsedComment.source.filename)}: {props.parsedComment.source.line}
</a>
</div>
Expand Down
3 changes: 3 additions & 0 deletions site/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class Icons extends React.Component {
<svg className='icon mr12'>
<use xlinkHref={`#icon-${icon}`} />
</svg>
<svg className='icon icon--s mr12'>
<use xlinkHref={`#icon-${icon}`} />
</svg>
<span className='color-gray'>{icon}</span>
</div>
);
Expand Down
4 changes: 2 additions & 2 deletions site/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ function buildRoutes() {
'Switches',
'Checkboxes',
'Radios',
'Triangles',
'Miscellaneous'
'Icons',
'Triangles'
];

// Build out secondary navigation
Expand Down
40 changes: 35 additions & 5 deletions src/icons.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* @memberof Icons
* @example
* <svg class='icon'><use xlink:href='#icon-bike'/></svg>
* <svg class='icon'><use xlink:href='#icon-paint'/></svg>
*/
.icon {
display: block;
Expand All @@ -33,21 +33,51 @@
*
* @memberof Icons
* @example
* <svg class='icon icon--s'><use xlink:href='#icon-bike'/></svg>
* <svg class='icon icon--s'><use xlink:href='#icon-document'/></svg>
*/
.icon--s {
height: 12px !important;
width: 12px !important;
height: 15px !important;
width: 15px !important;
}

/**
* Make an icon large.
*
* @memberof Icons
* @example
* <svg class='icon icon--l'><use xlink:href='#icon-bike'/></svg>
* <svg class='icon icon--l'><use xlink:href='#icon-star'/></svg>
*/
.icon--l {
height: 36px !important;
width: 36px !important;
}

/**
* Add to a wrapping element around an icon in order to align the icon with text and ensure the icon doesn't unexpectedly shift text line height. Note that this rule depends on an expected text line height of 1.5 to 1.66, so it does not work with `txt-h{number}` classes. See the `icon-inliner--heading` modifier to center icons in heading text.
*
* @memberof Icons
* @example
* <p class='txt-l'><span class='icon-inliner'><svg class='icon'><use xlink:href='#icon-clipboard'/></svg></span> Copy</p>
* <p class='txt-xl'>Ring the <span class='icon-inliner'><svg class='icon icon--l'><use xlink:href='#icon-bell'/></svg></span></p>
* <p class='txt-s'>Keep your <span class='icon-inliner'><svg class='icon icon--s'><use xlink:href='#icon-home'/></svg></span> safe from <span class='icon-inliner'><svg class='icon icon--s'><use xlink:href='#icon-bug'/></svg></span></p>
**/
.icon-inliner {
position: relative !important;
display: inline-flex !important;
vertical-align: top !important;
align-items: center !important;
justify-content: center !important;
height: 1em !important;
Copy link
Contributor

Choose a reason for hiding this comment

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

@samanpwbb: I think that conventionally we haven't been using !important unless the declaration corresponds directly to the class name. Is there a reason we need to use !important on these declarations?

top: 0.3em;
}

/**
* Modify the `icon-inliner` class so it works inside headings, which have an expected line height of 1.2 rather than 1.5 to 1.66.
*
* @memberof Icons
* @example
* <h1 class='txt-h1'>I <span class='icon-inliner icon-inliner--heading'><svg class='icon icon--l'><use xlink:href='#icon-heart'/></svg></span> New York.</p>
**/
.icon-inliner--heading {
top: 0.08em;
}
44 changes: 40 additions & 4 deletions test/__snapshots__/build-css.jest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1319,13 +1319,31 @@ input:checked:disabled + .toggle{
width:18px;
}
.icon--s{
height:12px !important;
width:12px !important;
height:15px !important;
width:15px !important;
}
.icon--l{
height:36px !important;
width:36px !important;
}
.icon-inliner{
position:relative !important;
display:-webkit-inline-flex !important;
display:-ms-inline-flexbox !important;
display:inline-flex !important;
vertical-align:top !important;
-webkit-align-items:center !important;
-ms-flex-align:center !important;
align-items:center !important;
-webkit-justify-content:center !important;
-ms-flex-pack:center !important;
justify-content:center !important;
height:1em !important;
top:0.3em;
}
.icon-inliner--heading{
top:0.08em;
}
.grid{
display:-webkit-flex !important;
display:-ms-flexbox !important;
Expand Down Expand Up @@ -17769,13 +17787,31 @@ input:checked:disabled + .toggle{
width:18px;
}
.icon--s{
height:12px !important;
width:12px !important;
height:15px !important;
width:15px !important;
}
.icon--l{
height:36px !important;
width:36px !important;
}
.icon-inliner{
position:relative !important;
display:-webkit-inline-flex !important;
display:-ms-inline-flexbox !important;
display:inline-flex !important;
vertical-align:top !important;
-webkit-align-items:center !important;
-ms-flex-align:center !important;
align-items:center !important;
-webkit-justify-content:center !important;
-ms-flex-pack:center !important;
justify-content:center !important;
height:1em !important;
top:0.3em;
}
.icon-inliner--heading{
top:0.08em;
}
.grid{
display:-webkit-flex !important;
display:-ms-flexbox !important;
Expand Down