Skip to content

Commit da86c2a

Browse files
authored
Enable Contribute page to respond to screen size changes (#232)
* Add clean and serve scripts * Improve code highlighting on contribute * Ensure we have the latest prismjs and prism-react-renderer * Shorten example description to make it easier to read and reduce screen sizes where overflow is required * Fix JSON5 syntax highlighting * Specify markdown sytnax highlighting for front matter samples. Markdown front matter highlighting will come to PrismJS in the next version (PrismJS/prism#2634) * Trim whitespace and newlines from the end of code samples * Add scrollbars to code examples Enables the Contribute page to shrink according to screen size * Allow code examples to be scrollable by keyboard users * Disable eslint warning for tabIndex on pre element
1 parent c1297ae commit da86c2a

File tree

4 files changed

+38
-17
lines changed

4 files changed

+38
-17
lines changed

research/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
"license": "MIT",
1414
"scripts": {
1515
"build": "gatsby build",
16+
"clean": "gatsby clean",
17+
"serve": "gatsby serve",
1618
"start": "gatsby develop"
1719
},
1820
"husky": {
@@ -62,8 +64,8 @@
6264
"lint-staged": "^10.1.2",
6365
"lodash": "^4.17.15",
6466
"prettier": "^2.0.4",
65-
"prism-react-renderer": "^1.0.2",
66-
"prismjs": "^1.20.0",
67+
"prism-react-renderer": "^1.1.1",
68+
"prismjs": "^1.22.0",
6769
"prop-types": "^15.7.2",
6870
"react": "^16.13.1",
6971
"react-dom": "^16.13.1",

research/src/components/layout.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,36 @@ import Header from './header'
1111
import Navigation from './navigation'
1212
import ComponentLayout from './component-layout'
1313

14+
// Add JSON5 language support to Prism
15+
import Prism from 'prism-react-renderer/prism'
16+
17+
// Need to create the Prism global before importing new languages
18+
;(typeof global !== 'undefined' ? global : window).Prism = Prism
19+
require('prismjs/components/prism-json5')
20+
1421
const components = {
1522
pre: (props) => {
1623
// get the code content from the compiled `pre > code`
1724
const code = props.children
18-
const exampleCode = code.props.children
25+
const exampleCode = code.props.children.trimEnd()
1926
const language = (code.props.className || '').replace('language-', '')
2027

2128
return (
2229
<Highlight {...defaultProps} theme={vsDark} code={exampleCode} language={language}>
2330
{({ className, style, tokens, getLineProps, getTokenProps }) => (
24-
<pre className={className} style={{ ...style, padding: '0.25rem 0.5rem' }}>
31+
<pre
32+
className={className}
33+
style={{
34+
...style,
35+
padding: '0.25rem 0.5rem',
36+
overflow: 'auto',
37+
}}
38+
// Adding tabIndex to this non-interactive pre element to allow
39+
// keyboard users to scroll this pre element using only the keyboard
40+
tabIndex={0} // eslint-disable-line jsx-a11y/no-noninteractive-tabindex
41+
role="region"
42+
aria-label="Code example"
43+
>
2544
{tokens.map((line, i) => (
2645
<div {...getLineProps({ line, key: i })}>
2746
{line.map((token, key) => (
@@ -74,7 +93,7 @@ const Layout = ({ children, pageContext }) => {
7493
>
7594
<Navigation style={{ marginRight: '2em' }} />
7695

77-
<div style={{ flex: '1' }}>
96+
<div style={{ flex: '1 1 auto', minWidth: 0 }}>
7897
<ContentWrapper frontmatter={frontmatter}>{children}</ContentWrapper>
7998
</div>
8099
</div>

research/src/pages/contribute.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Add the `$schema` key pointing to our `design-system.schema.json5` schema and co
8181
{
8282
$schema: '../schemas/design-system.schema.json5',
8383
name: 'Ant Design',
84-
description: 'A design system with values of Nature and Determinacy for better user experience of enterprise applications.',
84+
description: 'An enterprise-class UI design language and React UI library.',
8585
url: 'http://ant.design',
8686
by: 'AFX',
8787
}
@@ -99,7 +99,7 @@ experienced either visually, by keyboard, or narration.
9999
{
100100
$schema: '../schemas/design-system.schema.json5',
101101
name: 'Ant Design',
102-
description: 'A design system with values of Nature and Determinacy for better user experience of enterprise applications.',
102+
description: 'An enterprise-class UI design language and React UI library.',
103103
url: 'http://ant.design',
104104
by: 'AFX',
105105
components: [{ name: 'Button' }],
@@ -198,7 +198,7 @@ The `pathToProposal` key tells your research page where its proposal page is hos
198198

199199
Example:
200200

201-
```
201+
```markdown
202202
---
203203
name: Test
204204
path: /components/test.research
@@ -241,7 +241,7 @@ The proposal page will summarize your findings, conclusions, and unresolved poin
241241
Define your proposal page front matter.
242242
The `pathToResearch` key tells your proposal page where its research page is hosted.
243243

244-
```
244+
```markdown
245245
---
246246
menu: Proposals
247247
name: Your Component

research/yarn.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11943,15 +11943,15 @@ pretty-format@^25.5.0:
1194311943
ansi-styles "^4.0.0"
1194411944
react-is "^16.12.0"
1194511945

11946-
prism-react-renderer@^1.0.2:
11947-
version "1.0.2"
11948-
resolved "https://registry.yarnpkg.com/prism-react-renderer/-/prism-react-renderer-1.0.2.tgz#3bb9a6a42f76fc049b03266298c7068fdd4b7ea9"
11949-
integrity sha512-0++pJyRfu4v2OxI/Us/5RLui9ESDkTiLkVCtKuPZYdpB8UQWJpnJQhPrWab053XtsKW3oM0sD69uJ6N9exm1Ag==
11946+
prism-react-renderer@^1.1.1:
11947+
version "1.1.1"
11948+
resolved "https://registry.yarnpkg.com/prism-react-renderer/-/prism-react-renderer-1.1.1.tgz#1c1be61b1eb9446a146ca7a50b7bcf36f2a70a44"
11949+
integrity sha512-MgMhSdHuHymNRqD6KM3eGS0PNqgK9q4QF5P0yoQQvpB6jNjeSAi3jcSAz0Sua/t9fa4xDOMar9HJbLa08gl9ug==
1195011950

11951-
prismjs@^1.20.0:
11952-
version "1.20.0"
11953-
resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.20.0.tgz#9b685fc480a3514ee7198eac6a3bf5024319ff03"
11954-
integrity sha512-AEDjSrVNkynnw6A+B1DsFkd6AVdTnp+/WoUixFRULlCLZVRZlVQMVWio/16jv7G1FscUxQxOQhWwApgbnxr6kQ==
11951+
prismjs@^1.22.0:
11952+
version "1.22.0"
11953+
resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.22.0.tgz#73c3400afc58a823dd7eed023f8e1ce9fd8977fa"
11954+
integrity sha512-lLJ/Wt9yy0AiSYBf212kK3mM5L8ycwlyTlSxHBAneXLR0nzFMlZ5y7riFPF3E33zXOF2IH95xdY5jIyZbM9z/w==
1195511955
optionalDependencies:
1195611956
clipboard "^2.0.0"
1195711957

0 commit comments

Comments
 (0)