generated from nl-design-system/example
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: use rol="image"& aria-labelledby intead of svg title - [x] use SVGO as an optimizer - [x] add test - [x] improve accessibility by remove hardcoded title from SVG and use rol="image"& aria-labelledby intead - [x] use `font-size` instead of `width, height` to control size - [x] auto generate icons component, names - [x] add new icons - [x] update storybook with the new icons
- Loading branch information
1 parent
b1ad9b1
commit 5e2215e
Showing
102 changed files
with
11,300 additions
and
7,949 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
dist/ | ||
www/ | ||
loader/ | ||
|
||
*~ | ||
*.sw[mnpcod] | ||
*.log | ||
*.lock | ||
*.tmp | ||
*.tmp.* | ||
log.txt | ||
*.sublime-project | ||
*.sublime-workspace | ||
|
||
.stencil/ | ||
.idea/ | ||
.vscode/ | ||
.sass-cache/ | ||
.versions/ | ||
node_modules/ | ||
$RECYCLE.BIN/ | ||
|
||
.DS_Store | ||
Thumbs.db | ||
UserInterfaceState.xcuserstate | ||
.env |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* eslint-env node */ | ||
const fs = require('fs'); | ||
const lodash = require('lodash'); | ||
const argv = require('minimist')(process.argv.slice(2), { | ||
string: ['prefix', 'path'], | ||
}); | ||
const path = require('path'); | ||
const { | ||
component, | ||
test, | ||
generateIconsName, | ||
generateIcons, | ||
style, | ||
iconContainerComponent, | ||
} = require('./component_templates.js'); | ||
|
||
const { kebabCase } = lodash; | ||
const componentPrefix = `${argv.prefix}-`; | ||
const componentsPath = argv.path; | ||
const iconRapperComponent = `${componentPrefix}container`; | ||
|
||
if (fs.existsSync(componentsPath)) throw new Error(`A component with this name already exists: ${componentsPath}`); | ||
|
||
if (!componentsPath) throw new Error('You must include a components path name.'); | ||
|
||
fs.mkdirSync(componentsPath, { recursive: true }); | ||
|
||
function writeFileErrorHandler(err) { | ||
if (err) throw err; | ||
} | ||
|
||
const directoryPath = path.join(__dirname, '../tmp/optimized-svgs'); | ||
|
||
fs.readdir(directoryPath, function (err, files) { | ||
//handling error | ||
if (err) { | ||
console.error('Unable to scan directory: ' + err); | ||
return; | ||
} | ||
|
||
const iconsNames = files.map((file) => `${componentPrefix}${kebabCase(file.replace('.svg', ''))}`); | ||
|
||
files.forEach(function (file) { | ||
const fileName = `${componentPrefix}${kebabCase(file.replace('.svg', ''))}`; | ||
const formattedName = kebabCase(fileName); | ||
const dir = `${componentsPath}/${formattedName}`; | ||
|
||
fs.readFile(path.join(directoryPath, file), 'utf8', function (err, svg) { | ||
if (err) { | ||
console.error(err); | ||
return; | ||
} | ||
|
||
// throw an error if the file already exists | ||
if (fs.existsSync(dir)) throw new Error('A component with that name already exists.'); | ||
|
||
// create the folder | ||
fs.mkdirSync(dir); | ||
fs.writeFile( | ||
`${dir}/${formattedName}.stencil.tsx`, | ||
component(fileName, svg, iconRapperComponent), | ||
writeFileErrorHandler, | ||
); | ||
fs.writeFile(`${dir}/${formattedName}.spec.tsx`, test(fileName), writeFileErrorHandler); | ||
}); | ||
}); | ||
|
||
fs.writeFile(`${componentsPath}/icon-set.json`, generateIconsName(iconsNames), writeFileErrorHandler); | ||
fs.writeFile(`${componentsPath}/icons.js`, generateIcons(iconsNames), writeFileErrorHandler); | ||
}); | ||
|
||
const createIconWrapperComponent = () => { | ||
const dir = `${componentsPath}/${iconRapperComponent}`; | ||
const cssValue = `.${iconRapperComponent} { | ||
display: inline-block; | ||
color: var(--${componentPrefix}color); | ||
font-size: var(--${componentPrefix}size); | ||
}`; | ||
fs.mkdirSync(dir); | ||
fs.writeFile( | ||
`${dir}/${iconRapperComponent}.stencil.tsx`, | ||
iconContainerComponent(iconRapperComponent, '<slot/>'), | ||
writeFileErrorHandler, | ||
); | ||
fs.writeFile(`${dir}/${iconRapperComponent}.space.tsx`, test(iconRapperComponent), writeFileErrorHandler); | ||
fs.writeFile(`${dir}/${iconRapperComponent}.scss`, style(cssValue), writeFileErrorHandler); | ||
}; | ||
createIconWrapperComponent(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* eslint-disable no-undef */ | ||
const lodash = require('lodash'); | ||
const { camelCase, kebabCase, upperFirst } = lodash; | ||
|
||
exports.component = (name, children, container) => { | ||
const ComponentName = upperFirst(camelCase(name)); | ||
const webComponentName = kebabCase(name); | ||
|
||
return `import { Component, h } from '@stencil/core'; | ||
@Component({ | ||
tag: '${webComponentName}', | ||
shadow: true, | ||
}) | ||
export class ${ComponentName} { | ||
render() { | ||
return ( | ||
<${container}> | ||
${children} | ||
</${container}> | ||
); | ||
} | ||
} | ||
`; | ||
}; | ||
|
||
exports.iconContainerComponent = (name, children) => { | ||
const ComponentName = upperFirst(camelCase(name)); | ||
const webComponentName = kebabCase(name); | ||
|
||
return `import { Component, h } from '@stencil/core'; | ||
@Component({ | ||
tag: '${webComponentName}', | ||
styleUrl: './${webComponentName}.scss', | ||
shadow: true, | ||
}) | ||
export class ${ComponentName} { | ||
render() { | ||
return ( | ||
<div class='${webComponentName}'> | ||
${children} | ||
</div> | ||
); | ||
} | ||
} | ||
`; | ||
}; | ||
|
||
exports.test = (name) => { | ||
const ComponentName = upperFirst(camelCase(name)); | ||
const webComponentName = kebabCase(name); | ||
return `import { ${ComponentName} } from './${webComponentName}.stencil'; | ||
describe('${ComponentName}', () => { | ||
it('builds', () => { | ||
expect(new ${ComponentName}()).toBeTruthy(); | ||
}); | ||
}); | ||
`; | ||
}; | ||
|
||
exports.generateIconsName = (iconsNames) => { | ||
return JSON.stringify(iconsNames); | ||
}; | ||
|
||
exports.generateIcons = (iconsNames) => { | ||
return `const icons = { | ||
${iconsNames.map((icon) => `\n${upperFirst(camelCase(icon))}`)} | ||
}`; | ||
}; | ||
|
||
exports.style = (value) => value; |
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Config } from '@stencil/core'; | ||
|
||
export const config: Config = { | ||
namespace: 'utrecht', | ||
outputTargets: [ | ||
{ | ||
type: 'dist', | ||
esmLoaderPath: '../loader', | ||
}, | ||
{ | ||
type: 'dist-custom-elements', | ||
}, | ||
{ | ||
type: 'docs-readme', | ||
}, | ||
{ | ||
type: 'www', | ||
serviceWorker: null, // disable service workers | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
export default { | ||
multipass: true, | ||
js2svg: { | ||
indent: 2, | ||
pretty: true, | ||
}, | ||
plugins: [ | ||
"preset-default", | ||
"removeDimensions", | ||
"removeTitle", | ||
"convertStyleToAttrs", | ||
{ | ||
name: "removeAttrs", | ||
params: { | ||
attrs: ["path:(fill|stroke)", "fill"], | ||
}, | ||
}, | ||
{ | ||
name: "sortAttrs", | ||
params: { | ||
xmlnsOrder: "alphabetical", | ||
}, | ||
}, | ||
{ | ||
name: "addAttributesToSVGElement", | ||
params: { | ||
attributes: [ | ||
{ | ||
fill: "CurrentColor", | ||
}, | ||
{ | ||
width: "1em", | ||
}, | ||
{ | ||
height: "1em", | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"compilerOptions": { | ||
"allowSyntheticDefaultImports": true, | ||
"allowUnreachableCode": false, | ||
"declaration": false, | ||
"experimentalDecorators": true, | ||
"skipLibCheck": true, | ||
"lib": ["dom", "es2017"], | ||
"moduleResolution": "node", | ||
"module": "esnext", | ||
"target": "es2017", | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"jsx": "react", | ||
"jsxFactory": "h" | ||
}, | ||
"include": ["src"], | ||
"exclude": ["node_modules"] | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.