Skip to content

Commit

Permalink
Add Link
Browse files Browse the repository at this point in the history
  • Loading branch information
finnhvman committed Mar 25, 2019
1 parent aacd697 commit f09a5bb
Show file tree
Hide file tree
Showing 8 changed files with 234 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
<p class="matter-secondary-text">I am a paragraph</p>
```

### Links
```html
<!-- Link Markup (does not override font properties); Class: matter-link -->
<a class="matter-link" href="https://github.com/finnhvman/matter">Link</a>
```

### Progress Indicators
```html
<!-- Progress Markup (indeterminate); Classes: matter-progress-linear, matter-progress-circular -->
Expand Down Expand Up @@ -136,6 +142,7 @@ Click the link of a component in the next section to find more examples of its u
* [x] [Text](./src/components/buttons/text)
* [x] [Unelevated](./src/components/buttons/unelevated)
* [x] [Colors](./src/utilities/colors)
* [x] [Links](./src/components/links)
* [x] Progress Indicators
* [x] [Circular](./src/components/progress/circular)
* [x] [Linear](./src/components/progress/linear)
Expand Down
24 changes: 24 additions & 0 deletions dist/matter.css
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,30 @@
.matter-button-text:disabled::after {
opacity: 0;
}
/* Link */
.matter-link {
--matter-helper-theme: var(--matter-theme-rgb, var(--matter-primary-rgb, 33, 150, 243));
--matter-helper-safari1: rgba(var(--matter-helper-theme), 0.12);
border-radius: 4px;
color: rgb(var(--matter-helper-theme));
text-decoration: none;
transition: background-color 0.2s, box-shadow 0.2s;
}
/* Hover */
.matter-link:hover {
text-decoration: underline;
}
/* Focus */
.matter-link:focus {
background-color: var(--matter-helper-safari1);
box-shadow: 0 0 0 0.16em var(--matter-helper-safari1);
outline: none;
}
/* Active */
.matter-link:active {
background-color: transparent;
box-shadow: none;
}
/* Progress Circular */
.matter-progress-circular {
--matter-helper-theme: var(--matter-theme-rgb, var(--matter-primary-rgb, 33, 150, 243));
Expand Down
2 changes: 1 addition & 1 deletion dist/matter.min.css

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/components/components.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
/* Button Text */
@import "./buttons/text/button-text.css";

/* Link */
@import "./links/link.css";

/* Progress Circular */
@import "./progress/circular/progress-circular.css";

Expand Down
26 changes: 26 additions & 0 deletions src/components/links/link.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.matter-link {
--matter-helper-theme: var(--matter-theme-rgb, var(--matter-primary-rgb, 33, 150, 243));
--matter-helper-safari1: rgba(var(--matter-helper-theme), 0.12);
border-radius: 4px;
color: rgb(var(--matter-helper-theme));
text-decoration: none;
transition: background-color 0.2s, box-shadow 0.2s;
}

/* Hover */
.matter-link:hover {
text-decoration: underline;
}

/* Focus */
.matter-link:focus {
background-color: var(--matter-helper-safari1);
box-shadow: 0 0 0 0.16em var(--matter-helper-safari1);
outline: none;
}

/* Active */
.matter-link:active {
background-color: transparent;
box-shadow: none;
}
1 change: 1 addition & 0 deletions src/components/links/link.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
23 changes: 23 additions & 0 deletions src/components/links/link.spec.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<link href="./link.css" rel="stylesheet">

The purpose of Matter is to provide the most easy-to-use but accurate implementation of <a href="https://material.io/design/guidelines-overview/" class="matter-link">Material Design Components</a>.

Matter has probably the lowest entry-barrier among Material Design Component libraries. The only technical knowledge needed to use it is basic <a href="https://en.wikipedia.org/wiki/HTML5" class="matter-link">HTML5</a>. It doesn't rely on <a href="https://tc39.github.io" class="matter-link">JavaScript</a>, it only needs one to three HTML elements and a CSS class per component to work. The markup of the components is semantic by design.

Matter is built with theming in mind. Its components can be customized by specifying certain colors and/or fonts. The granularity of customization is variable: components can be themed on global level, component level, component instance level, or on any level between.

<br/><br/>

<a class="matter-link" href="https://developer.mozilla.org/en-US/docs/Web/CSS/font-size" style="font-size: large;">Large</a>

<br/><br/>

<a class="matter-link" href="https://developer.mozilla.org/en-US/docs/Web/CSS/font-size">Medium</a>

<br/><br/>

<a class="matter-link" href="https://developer.mozilla.org/en-US/docs/Web/CSS/font-size" style="font-size: small;">Small</a>

<br/><br/>

<a id="xmas" class="matter-link" href="https://english.stackexchange.com/questions/84564/a-case-that-exhibits-all-the-possible-conditions-a-subject-can-suffer-from" style="display: inline-block; width: 80px; font-family: 'Roboto', 'Segoe UI', BlinkMacSystemFont, system-ui, -apple-system; font-size: 16px;">Xmas Tree</a>
149 changes: 149 additions & 0 deletions src/components/links/link.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import { setUp, tearDown } from '../../../test/helpers/fixture.js';
import { capture3x } from '../../../test/helpers/capture.js';
import { isBrowser, isBrowserNot } from '../../../test/helpers/browser.js';

const SPACING = 4;

// transparent
const tp = { a: 0 };

describe('Link', () => {

[
{
label: 'normal',
states: {},
textColor: { r: 33, g: 150, b: 243, a: 255 },
bodyColor: tp
},
{
label: 'hover',
states: {
'#xmas.matter-link': [ 'hover' ]
},
textColor: { r: 33, g: 150, b: 243, a: 255 },
bodyColor: tp,
underline: true
},
{
label: 'focus',
states: {
'#xmas.matter-link': [ 'focus' ]
},
textColor: { r: 33, g: 150, b: 243, a: 255 },
bodyColor: { r: [17, 41], g: [136, 162], b: [237, 255], a: [28, 34] }
},
{
label: 'active',
states: {
'#xmas.matter-link': [ 'active' ]
},
textColor: { r: 33, g: 150, b: 243, a: 255 },
bodyColor: tp,
},
{
label: 'hover & focus',
states: {
'#xmas.matter-link': [ 'hover', 'focus' ]
},
textColor: { r: 33, g: 150, b: 243, a: 255 },
bodyColor: { r: [17, 41], g: [136, 162], b: [237, 255], a: [28, 34] },
underline: true
},
{
label: 'hover & active',
states: {
'#xmas.matter-link': [ 'hover', 'active' ]
},
textColor: { r: 33, g: 150, b: 243, a: 255 },
bodyColor: tp,
underline: true
},
{
label: 'focus & active',
states: {
'#xmas.matter-link': [ 'focus', 'active' ]
},
textColor: { r: 33, g: 150, b: 243, a: 255 },
bodyColor: tp
},
{
label: 'hover, focus & active',
states: {
'#xmas.matter-link': [ 'hover', 'focus', 'active' ]
},
textColor: { r: 33, g: 150, b: 243, a: 255 },
bodyColor: tp,
underline: true
},
{
label: 'customized',
states: {
'#xmas.matter-link': {
style: '--matter-primary-rgb: 255, 0, 0;display: inline-block; width: 80px; font-family: "Roboto", "Segoe UI", BlinkMacSystemFont, system-ui, -apple-system; font-size: 16px;'
}
},
textColor: { r: 255, g: 0, b: 0, a: 255 },
bodyColor: tp
},
{
label: 'customized & focus',
states: {
'#xmas.matter-link': {
style: '--matter-primary-rgb: 255, 0, 0;display: inline-block; width: 80px; font-family: "Roboto", "Segoe UI", BlinkMacSystemFont, system-ui, -apple-system; font-size: 16px;',
focus: ''
}
},
textColor: { r: 255, g: 0, b: 0, a: 255 },
bodyColor: { r: [254, 255], g: 0, b: 0, a: [28, 34] },
}
].forEach((suite) => {

describe(`in ${suite.label} state`, () => {

let style;
let link;
let width;
let height;
let context;

beforeAll(async () => {
style = setUp('src/components/links/link', suite.states);

link = document.querySelector('#xmas');
const rect = link.getBoundingClientRect();
width = rect.width;
height = rect.height;
context = await capture3x(link, style, SPACING);
});

afterAll(() => {
tearDown();
});

it(`should have dominant ${JSON.stringify(suite.bodyColor).replace(/"/g, '')} color`, () => {
const component = context.getImageData3x(-4, -4, width + 8, height + 8);

expect(component).toResembleColor(suite.bodyColor);
});

it('should have caption text', () => {
const caption = context.getImageData3x(0, 1, width, 15);

expect(link.innerText).toBe('Xmas Tree');
expect(caption).toResembleText('Xmas Tree', suite.textColor, suite.bodyColor);
});

it(`should${suite.underline ? '' : ' not'} have underline`, () => {
const underline = context.getImageData3x(0, 16, width, 1);
const underlineFF = context.getImageData3x(0, 18, width, 1);

isBrowserNot('Firefox') && expect(underline).toResembleColor(suite.underline ? suite.textColor : suite.bodyColor);
isBrowser('Firefox') && expect(underlineFF).toResembleColor(suite.underline ? suite.textColor : suite.bodyColor);
});

});

});

});

0 comments on commit f09a5bb

Please sign in to comment.