Skip to content

Commit d921547

Browse files
authored
refactor: RuleCard component for items rendered in rules page (act-rules#68)
1 parent a4df537 commit d921547

File tree

6 files changed

+140
-125
lines changed

6 files changed

+140
-125
lines changed

src/components/layout.scss

Lines changed: 1 addition & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -128,89 +128,7 @@ section.layout-container {
128128
}
129129
}
130130

131-
// Styles for rules page
132-
&.page-rules{
133-
.rules-listing {
134-
counter-reset: rule-item;
135-
136-
>article {
137-
border: 1px solid $sep;
138-
padding: 0.5rem;
139-
display: flex;
140-
flex-direction: column;
141-
position: relative;
142-
background-color: $bg-primary;
143-
144-
&:nth-child(2n) {
145-
background-color: lighten($sep, 2%);
146-
&::before{
147-
background-color: lighten($sep, 2%);
148-
}
149-
}
150-
151-
// Index/ counter
152-
&:before {
153-
counter-increment: rule-item;
154-
content: counter(rule-item);
155-
position: absolute;
156-
width: 30px;
157-
left: -31px;
158-
top: -1px;
159-
border: 1px solid $sep;
160-
border-right: none;
161-
font-weight: bold;
162-
text-align: center;
163-
padding: 11px 0;
164-
background-color: $bg-primary;
165-
}
166-
167-
div.meta {
168-
h3.heading,
169-
span.heading {
170-
padding: 0.25rem 0.5rem;
171-
background-color: $sep;
172-
border: 1px solid $transparent;
173-
text-transform: capitalize;
174-
display: inline-block;
175-
font-weight: bold;
176-
margin-top: 1em;
177-
font-size: 90%;
178-
color: inherit;
179-
cursor: auto;
180-
&:hover {
181-
text-decoration: none;
182-
}
183-
}
184-
a.sc-item {
185-
cursor: pointer;
186-
text-decoration: none;
187-
text-transform: capitalize;
188-
&:hover {
189-
color: $accent;
190-
}
191-
}
192-
}
193-
194-
>section {
195-
flex: 1;
196-
>a{
197-
text-decoration: none;
198-
}
199-
h2{
200-
margin: 0;
201-
margin-bottom: 0.5rem;
202-
>p{
203-
margin: 0;
204-
}
205-
}
206-
&:last-child{
207-
border-bottom: none;
208-
}
209-
}
210-
}
211-
}
212-
}
213-
131+
214132
// Styles for glossary page
215133
&.page-glossary{
216134
.listing {
@@ -402,13 +320,6 @@ section.layout-container {
402320
section.layout-container {
403321
> main {
404322
.page-container {
405-
&.page-rules {
406-
.rules-listing {
407-
> article {
408-
flex-direction: column;
409-
}
410-
}
411-
}
412323
&.page-glossary {
413324
.listing {
414325
> article {

src/components/rule-card.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import React from 'react'
2+
import PropTypes from 'prop-types'
3+
import showdown from 'showdown'
4+
5+
import AccessibilityRequirements from './accessibility_requirements'
6+
import CountImplementations from './count-implementations'
7+
8+
import { getInputRulesForRule } from '../utils/render-fragments'
9+
10+
import './rule-card.scss'
11+
12+
const RuleCard = ({ id = '', name = '', description = '', accessibilityRequirements, inputRules, allRules }) => {
13+
const converter = new showdown.Converter()
14+
15+
return (
16+
<article className="ruleCard">
17+
<section>
18+
{/* rule id */}
19+
<a href={id}>
20+
<h2
21+
dangerouslySetInnerHTML={{
22+
__html: converter.makeHtml(name),
23+
}}
24+
/>
25+
</a>
26+
{/* rule sc's */}
27+
<AccessibilityRequirements accessibility_requirements={accessibilityRequirements} type="text" />
28+
{/* input rules */}
29+
{getInputRulesForRule(inputRules, allRules.edges, true)}
30+
{/* implementation count */}
31+
<CountImplementations ruleId={id} />
32+
{/* rule description */}
33+
<div
34+
dangerouslySetInnerHTML={{
35+
__html: converter.makeHtml(description),
36+
}}
37+
/>
38+
</section>
39+
</article>
40+
)
41+
}
42+
43+
RuleCard.propTypes = {
44+
id: PropTypes.string.isRequired,
45+
name: PropTypes.string.isRequired,
46+
description: PropTypes.array.isRequired,
47+
accessibilityRequirements: PropTypes.object,
48+
inputRules: PropTypes.array,
49+
allRules: PropTypes.array,
50+
}
51+
52+
export default RuleCard

src/components/rule-card.scss

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
@import '../styles/variables.scss';
2+
@import '../styles/mixins.scss';
3+
4+
article.ruleCard {
5+
padding: 1rem;
6+
margin-bottom: 1.5rem;
7+
display: flex;
8+
flex-direction: column;
9+
background-color: rgba($sep, 0.5);
10+
box-shadow: 0px 0px 12px rgba($black, 0.2);
11+
12+
&:hover {
13+
outline: 2px solid $accent;
14+
}
15+
16+
div.meta {
17+
h3.heading,
18+
span.heading {
19+
padding: 0.25rem 0.5rem;
20+
background-color: $sep;
21+
border: 1px solid $transparent;
22+
text-transform: capitalize;
23+
display: inline-block;
24+
font-weight: bold;
25+
margin-top: 1em;
26+
font-size: 90%;
27+
color: inherit;
28+
cursor: auto;
29+
&:hover {
30+
text-decoration: none;
31+
}
32+
}
33+
a.sc-item {
34+
cursor: pointer;
35+
text-decoration: none;
36+
text-transform: capitalize;
37+
&:hover {
38+
color: $accent;
39+
}
40+
}
41+
}
42+
43+
> section {
44+
flex: 1;
45+
> a {
46+
text-decoration: none;
47+
}
48+
h2 {
49+
margin: 0;
50+
margin-bottom: 0.5rem;
51+
> p {
52+
margin: 0;
53+
}
54+
}
55+
&:last-child {
56+
border-bottom: none;
57+
}
58+
}
59+
}

src/pages/rules.js

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,33 @@ import React from 'react'
22
import { graphql } from 'gatsby'
33
import Layout from '../components/layout'
44
import SEO from '../components/seo'
5-
import showdown from 'showdown'
6-
import { getInputRulesForRule } from './../utils/render-fragments'
7-
import AccessibilityRequirements from '../components/accessibility_requirements'
8-
import CountImplementations from '../components/count-implementations'
5+
import RuleCard from '../components/rule-card'
6+
7+
import './rules.scss'
98

109
export default ({ location, data }) => {
1110
const { rules, allRules } = data
12-
const converter = new showdown.Converter()
1311

1412
return (
1513
<Layout location={location}>
1614
<SEO title="Rules" />
17-
<section className="page-container page-rules">
15+
<section className="page-rules">
1816
{/* Heading */}
1917
<h1>Rules</h1>
2018
{/* Table of rules */}
21-
<section className="rules-listing">
19+
<section>
2220
{rules.edges.map(({ node }) => {
23-
const { frontmatter, id, fields } = node
24-
const { name, description, input_rules } = frontmatter
25-
const { slug, fastmatterAttributes } = fields
26-
const { accessibility_requirements } = JSON.parse(fastmatterAttributes)
21+
const { frontmatter, fields } = node
2722
return (
28-
<article key={id}>
29-
<section>
30-
{/* rule id */}
31-
<a href={slug.replace('rules/', '')}>
32-
<h2
33-
dangerouslySetInnerHTML={{
34-
__html: converter.makeHtml(name),
35-
}}
36-
/>
37-
</a>
38-
{/* rule sc's */}
39-
<AccessibilityRequirements accessibility_requirements={accessibility_requirements} type="text" />
40-
{/* input rules */}
41-
{getInputRulesForRule(input_rules, allRules.edges, true)}
42-
{/* implementation count */}
43-
<CountImplementations ruleId={slug.replace('rules/', '')} />
44-
{/* rule description */}
45-
<div
46-
dangerouslySetInnerHTML={{
47-
__html: converter.makeHtml(description),
48-
}}
49-
/>
50-
</section>
51-
</article>
23+
<RuleCard
24+
key={frontmatter.id}
25+
id={frontmatter.id}
26+
name={frontmatter.name}
27+
description={frontmatter.description}
28+
accessibilityRequirements={JSON.parse(fields.fastmatterAttributes).accessibility_requirements}
29+
inputRules={frontmatter.input_rules}
30+
allRules={allRules}
31+
/>
5232
)
5333
})}
5434
</section>
@@ -69,6 +49,7 @@ export const query = graphql`
6949
fileAbsolutePath
7050
id
7151
frontmatter {
52+
id
7253
name
7354
description
7455
rule_type

src/pages/rules.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@import '../styles//variables.scss';
2+
@import '../styles/mixins.scss';
3+
4+
.page-rules {
5+
@include page-container-default-styles;
6+
}

src/styles/mixins.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
@mixin page-container-default-styles() {
6868
margin: 3rem 0;
6969
padding: 0 4rem;
70+
7071
h1 {
7172
border-bottom: 1px solid $sep;
7273
padding: 2rem 0;
@@ -76,6 +77,7 @@
7677
margin: 0;
7778
}
7879
}
80+
7981
h2,
8082
h3,
8183
h4,
@@ -85,4 +87,8 @@
8587
text-decoration: underline;
8688
}
8789
}
90+
91+
h2 {
92+
margin-top: 3rem;
93+
}
8894
}

0 commit comments

Comments
 (0)