Skip to content

Commit 00ce23f

Browse files
authored
Merge pull request #5 from PDFTron/lr-modal
Overlay components
2 parents acd07b1 + 34b7e5d commit 00ce23f

File tree

71 files changed

+1612
-488
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1612
-488
lines changed

.eslintrc.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser',
3+
parserOptions: { project: './tsconfig.lint.json' },
4+
plugins: ['react-hooks'],
5+
extends: [
6+
'plugin:jsx-a11y/recommended',
7+
'plugin:jest/recommended',
8+
'eslint:recommended',
9+
'plugin:react/recommended',
10+
'plugin:@typescript-eslint/eslint-recommended',
11+
'plugin:@typescript-eslint/recommended',
12+
13+
// Prettier overrides
14+
'prettier',
15+
'prettier/react',
16+
'prettier/@typescript-eslint',
17+
],
18+
settings: {
19+
react: { version: '16.8' },
20+
},
21+
env: {
22+
browser: true,
23+
es6: true,
24+
commonjs: true,
25+
node: true,
26+
jest: true,
27+
},
28+
rules: {
29+
// Turn on or modify rules.
30+
'prefer-const': 'error',
31+
'react-hooks/rules-of-hooks': 'error',
32+
'react-hooks/exhaustive-deps': 'error',
33+
'@typescript-eslint/no-unused-vars': [
34+
'error',
35+
{ ignoreRestSiblings: true, argsIgnorePattern: '^_' },
36+
],
37+
'@typescript-eslint/unbound-method': 'error',
38+
39+
// Turn off rules.
40+
'react/prop-types': 'off',
41+
'react/display-name': 'off',
42+
'@typescript-eslint/explicit-function-return-type': 'off',
43+
'@typescript-eslint/no-var-requires': 'off',
44+
'@typescript-eslint/no-empty-interface': 'off',
45+
'@typescript-eslint/camelcase': 'off',
46+
'@typescript-eslint/no-triple-slash-reference': 'off',
47+
'@typescript-eslint/no-non-null-assertion': 'off',
48+
'@typescript-eslint/ban-ts-ignore': 'off',
49+
'@typescript-eslint/no-use-before-define': 'off',
50+
},
51+
};

.eslintrc.yaml

Lines changed: 0 additions & 45 deletions
This file was deleted.

.storybook/preview.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@ addParameters({
5858

5959
// Since we do not add component description in code (instead inserting it
6060
// into a .md file) we extract it using the following.
61-
extractComponentDescription: (_c: unknown, { info }: { info: string | { info?: string; text?: string } }) => {
62-
if (typeof info === 'string') return info;
63-
if (info.info) return info.info;
64-
if (info.text) return info.text;
61+
extractComponentDescription: (_c: unknown, { readme }: { readme: string }) => {
62+
if (readme) return readme;
6563
return null;
6664
},
6765

scripts/make/file-content/componentStory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ export const componentStory = (componentName: string) =>
33
import { boolean, text } from '@storybook/addon-knobs';
44
import React from 'react';
55
import { ${componentName} } from '../${componentName}';
6-
import info from './README.md';
6+
import readme from './README.md';
77
8-
export default { title: 'Components/${componentName}', component: ${componentName}, parameters: { info } };
8+
export default { title: 'Components/${componentName}', component: ${componentName}, parameters: { readme } };
99
1010
export const Basic = () => (
1111
<${componentName}

scripts/parse_scss.js

Lines changed: 107 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,11 @@ async function createSassVariablesFile(ast) {
8585
fs.writeFileSync(`src/styles/_variables.scss`, fileContent);
8686
}
8787

88-
/**
89-
* Parse the mixins file and generate mixins mdx.
90-
*/
91-
async function mixins() {
92-
const url = 'src/styles/_mixins.scss';
93-
const docsUrl = 'src/__stories__/2_style/3_mixins.stories.mdx';
94-
const mixinsUrl = 'src/__stories__/2_style/mixins.ts';
88+
/* --- Mixins. --- */
9589

96-
const mixinsAst = getAST(url);
97-
const docsFile = fs.readFileSync(docsUrl);
90+
async function generateMixinsFile(input, output, transform, replace = v => v) {
91+
const mixinsAst = getAST(input);
92+
const docsFile = fs.readFileSync(transform);
9893

9994
const mixinLines = docsFile.toString().split('\n');
10095
const indexOfEntry = mixinLines.findIndex(l => l.includes('GENERATE_ENTRY'));
@@ -126,21 +121,27 @@ async function mixins() {
126121
const media = isMedia ? ` {\n // Content\n}` : '';
127122
return {
128123
include: `@include ${m.params}${media};`,
129-
code: css
130-
.slice(m.source.start.line - 2, m.source.end.line)
131-
.join('\n')
132-
.trim(),
124+
code: replace(
125+
css
126+
.slice(m.source.start.line - 2, m.source.end.line - 1)
127+
.filter(line => !line.includes('@mixin'))
128+
.map(line =>
129+
line.replace(' ', '').replace('@content;', '/* Content */'),
130+
)
131+
.join('\n')
132+
.trim(),
133+
),
133134
animation: animation && `\n\n${animation}`,
134135
};
135136
});
136137

137138
printFile(
138-
mixinsUrl,
139+
output,
139140
data.map(d => d.include),
140141
);
141142

142143
fs.writeFileSync(
143-
docsUrl,
144+
transform,
144145
`${pre}
145146
${data
146147
.map(
@@ -149,20 +150,89 @@ ${data
149150
150151
\`\`\`scss
151152
${d.code}${d.animation}
152-
\`\`\`
153-
`,
153+
\`\`\``,
154154
)
155-
.join('\n')}`,
155+
.join('\n')}
156+
`,
156157
);
157158
}
158159

160+
/**
161+
* Parse the mixins file and generate mixins mdx.
162+
*/
163+
async function mixins() {
164+
const url = 'src/styles/_mixins.scss';
165+
const docsUrl = 'src/__stories__/2_style/3_mixins.stories.mdx';
166+
const mixinsUrl = 'src/__stories__/2_style/generated/mixins.ts';
167+
168+
generateMixinsFile(url, mixinsUrl, docsUrl);
169+
}
170+
171+
/**
172+
* Parse breakpoints.
173+
*/
174+
async function breakpoints() {
175+
const url = 'src/styles/_breakpoints.scss';
176+
const breakpointsUrl = 'src/__stories__/2_style/generated/breakpoints.ts';
177+
const docsUrl = 'src/__stories__/2_style/4_breakpoints.stories.mdx';
178+
179+
const breakpointsAST = getAST(url);
180+
181+
const breakpointsNodes = breakpointsAST.nodes;
182+
183+
const declarations = (() => {
184+
const decl = [];
185+
186+
breakpointsNodes.forEach(n => {
187+
if (n.type !== 'decl') return;
188+
decl.push(n);
189+
});
190+
191+
return decl;
192+
})().map(({ prop, value }) => ({ prop, value }));
193+
194+
const mixins = breakpointsNodes.filter(n => n.name === 'mixin');
195+
const css = mixins[0].source.input.css.split('\n');
196+
197+
const data = mixins.map(m => {
198+
const code = css
199+
.slice(m.source.start.line - 2, m.source.end.line)
200+
.join('\n')
201+
.trim();
202+
const isOnly = m.params.includes('only');
203+
const declaration = declarations.find(decl => code.includes(decl.prop));
204+
const numValue = Number(declaration.value.replace('px', ''));
205+
return {
206+
params: m.params,
207+
min: isOnly ? undefined : numValue,
208+
max: isOnly ? numValue - 1 : undefined,
209+
...declaration,
210+
};
211+
});
212+
213+
printFile('src/__stories__/2_style/generated/breakpointRange.ts', data);
214+
215+
generateMixinsFile(url, breakpointsUrl, docsUrl, val => {
216+
let newVal = val;
217+
data.forEach(data => {
218+
const isMax = newVal.includes('max-width');
219+
if (isMax && data.max) {
220+
newVal = newVal.replace(data.prop, `${data.max}px`);
221+
} else if (!isMax && data.min) {
222+
newVal = newVal.replace(data.prop, `${data.min}px`);
223+
}
224+
newVal = newVal.replace(' - 1', '');
225+
});
226+
return newVal;
227+
});
228+
}
229+
159230
/**
160231
* Parse variables and themes files, generate variables and colors mdx.
161232
*/
162233
function main() {
163-
/* --- Generate mixins file. --- */
164-
165234
mixins();
235+
breakpoints();
166236

167237
const ast = getAST('src/styles/_theme.scss');
168238
const nodes = ast.nodes.find(n => n.selector === ':root').nodes;
@@ -175,32 +245,35 @@ function main() {
175245
const color = [];
176246
const zIndex = [];
177247
const padding = [];
178-
const breakpoint = [];
179248
const fontSize = [];
180249
const fontWeight = [];
181250
const borderRadius = [];
251+
const boxShadow = [];
252+
const focus = [];
182253
const other = [];
183254

184255
nodes.forEach(n => {
185256
if (n.type !== 'decl') return;
186257
if (n.prop.startsWith('--color')) return color.push(n);
187258
if (n.prop.startsWith('--z-index')) return zIndex.push(n);
188259
if (n.prop.startsWith('--padding')) return padding.push(n);
189-
if (n.prop.startsWith('--breakpoint')) return breakpoint.push(n);
190260
if (n.prop.startsWith('--font-size')) return fontSize.push(n);
191261
if (n.prop.startsWith('--font-weight')) return fontWeight.push(n);
192262
if (n.prop.startsWith('--border-radius')) return borderRadius.push(n);
263+
if (n.prop.startsWith('--box-shadow')) return boxShadow.push(n);
264+
if (n.prop.startsWith('--focus')) return focus.push(n);
193265
other.push(n);
194266
});
195267

196268
return {
197269
color,
198270
zIndex,
199271
padding,
200-
breakpoint,
201272
fontSize,
202273
fontWeight,
203274
borderRadius,
275+
boxShadow,
276+
focus,
204277
other,
205278
};
206279
})();
@@ -215,6 +288,7 @@ function main() {
215288
const gray = [];
216289
const blueGray = [];
217290
const contrast = [];
291+
const message = [];
218292
const other = [];
219293

220294
allColors.forEach(c => {
@@ -223,10 +297,11 @@ function main() {
223297
if (c.scss.startsWith('$color-gray')) return gray.push(c);
224298
if (c.scss.startsWith('$color-blue-gray')) return blueGray.push(c);
225299
if (c.scss.startsWith('$color-contrast')) return contrast.push(c);
300+
if (c.scss.startsWith('$color-message')) return message.push(c);
226301
other.push(c);
227302
});
228303

229-
return { theme, font, gray, blueGray, contrast, other };
304+
return { theme, font, gray, blueGray, contrast, message, other };
230305
})();
231306

232307
/* --- Map variables. --- */
@@ -235,7 +310,8 @@ function main() {
235310
const fontWeight = declarations.fontWeight.map(mapper);
236311
const padding = declarations.padding.map(mapper);
237312
const borderRadius = declarations.borderRadius.map(mapper);
238-
const breakpoint = declarations.breakpoint.map(mapper);
313+
const boxShadow = declarations.boxShadow.map(mapper);
314+
const focus = declarations.focus.map(mapper);
239315
const zIndex = declarations.zIndex.map(mapper);
240316
const other = declarations.other.map(mapper);
241317

@@ -245,13 +321,17 @@ function main() {
245321
fontWeight,
246322
padding,
247323
borderRadius,
248-
breakpoint,
324+
boxShadow,
325+
focus,
249326
zIndex,
250327
other,
251328
};
252329

253330
createSassVariablesFile(variableObject);
254-
printFile('src/__stories__/2_style/styleVariables.ts', variableObject);
331+
printFile(
332+
'src/__stories__/2_style/generated/styleVariables.ts',
333+
variableObject,
334+
);
255335
}
256336

257337
main();

src/__stories__/1_basics/2_getting-started.stories.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ the <LinkTo title="Style/Colors">Style section</LinkTo>.
4949
```scss
5050
@import "~@pdftron/webviewer-react-toolkit/dist/scss/_variables.scss";
5151
@import "~@pdftron/webviewer-react-toolkit/dist/scss/_mixins.scss";
52+
@import "~@pdftron/webviewer-react-toolkit/dist/scss/_breakpoints.scss";
5253
```
5354

5455
## Fonts (optional)

src/__stories__/2_style/1_colors.stories.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ div {
2828
}
2929
```
3030

31+
If you are using Sass, make sure you import the Sass variables file:
32+
33+
```scss
34+
@import "~@pdftron/webviewer-react-toolkit/dist/scss/_variables.scss";
35+
```
36+
3137
## Themes
3238

3339
The toolkit ships with a default light and dark theme To see what the colors

src/__stories__/2_style/2_variables.stories.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ div {
2828
}
2929
```
3030

31+
If you are using Sass, make sure you import the Sass variables file:
32+
33+
```scss
34+
@import "~@pdftron/webviewer-react-toolkit/dist/scss/_variables.scss";
35+
```
36+
3137
## Overriding
3238

3339
Since each value is a variable, and all Sass variables just point to the CSS

0 commit comments

Comments
 (0)