@televet/kibble-ui 0.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +397 -0
- package/build/components/Button/index.d.ts +5 -0
- package/build/index.d.ts +4 -0
- package/build/index.es.js +13886 -0
- package/build/index.es.js.map +1 -0
- package/build/index.js +13740 -0
- package/build/index.js.map +1 -0
- package/build/providers/ThemeProvider/ThemeProvider.d.ts +5 -0
- package/build/providers/ThemeProvider/index.d.ts +5 -0
- package/build/theme/blur.d.ts +12 -0
- package/build/theme/borders.d.ts +15 -0
- package/build/theme/breakpoints.d.ts +9 -0
- package/build/theme/colors.d.ts +193 -0
- package/build/theme/fontSizes.d.ts +17 -0
- package/build/theme/fontWeights.d.ts +13 -0
- package/build/theme/fonts.d.ts +7 -0
- package/build/theme/index.d.ts +32 -0
- package/build/theme/letterSpacings.d.ts +17 -0
- package/build/theme/lineHeights.d.ts +19 -0
- package/build/theme/radii.d.ts +13 -0
- package/build/theme/shadows.d.ts +27 -0
- package/build/theme/sizes.d.ts +27 -0
- package/build/theme/space.d.ts +37 -0
- package/build/theme/theme.d.ts +3 -0
- package/build/theme/tokens/colors/colors.d.ts +190 -0
- package/build/theme/tokens/fonts/fonts.d.ts +6 -0
- package/build/theme/transition.d.ts +28 -0
- package/build/theme/zIndeces.d.ts +17 -0
- package/package.json +126 -0
package/README.md
ADDED
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
# Kibble
|
|
2
|
+
|
|
3
|
+
Kibble is a React component library for use at TeleVet.
|
|
4
|
+
|
|
5
|
+
https://televet.github.io/kibble-ui/
|
|
6
|
+
|
|
7
|
+
## Usage within a Televet Project
|
|
8
|
+
|
|
9
|
+
### New Project Setup
|
|
10
|
+
|
|
11
|
+
If your project does not include a .npmrc, create it and add the following:
|
|
12
|
+
|
|
13
|
+
`//registry.npmjs.org/:_authToken=${NPM_TOKEN}`
|
|
14
|
+
|
|
15
|
+
#### Add NPM_TOKEN environment variable
|
|
16
|
+
|
|
17
|
+
In your .bash_profile or .zshrc
|
|
18
|
+
`export NPM_TOKEN=SOME_TOKEN`
|
|
19
|
+
|
|
20
|
+
#### Install in project
|
|
21
|
+
|
|
22
|
+
`npm i --save @televet/kibble-ui`
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
import {
|
|
26
|
+
ThemeProvider,
|
|
27
|
+
theme,
|
|
28
|
+
Button,
|
|
29
|
+
.... and all other components
|
|
30
|
+
} from 'kibble-ui';
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Development Setup
|
|
34
|
+
|
|
35
|
+
`$ npm i` - Install dependencies.
|
|
36
|
+
`npm run start` runs CRA in development mode with hot reloading. Open http://localhost:3000 to see your code live.
|
|
37
|
+
|
|
38
|
+
#### Linking Projects for Local Development
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
cd ~/kibble-ui # go into the package directory
|
|
42
|
+
npm run build # ensure there are build files available for the package to reference
|
|
43
|
+
npm link ../clinic-web/node_modules/react # links kibble-ui react to clinic-web react to prevent two versions of react. See reference to this error here: https://reactjs.org/warnings/invalid-hook-call-warning.html#duplicate-react
|
|
44
|
+
|
|
45
|
+
# You may need to run the link commands using sudo if you get a permissions error
|
|
46
|
+
|
|
47
|
+
# Navigate to project directory and update package.json to point to your local copy of kibble-ui
|
|
48
|
+
# "@televet/kibble-ui": "./../kibble-ui"
|
|
49
|
+
|
|
50
|
+
cd ~/clinic-web # go into a project directory
|
|
51
|
+
npm install # fresh install without kibble ui
|
|
52
|
+
|
|
53
|
+
# To see what links you've created globally you can run the following command
|
|
54
|
+
npm list -g
|
|
55
|
+
|
|
56
|
+
# To see what links an individual project is currently using run the following command from within that projects root folder
|
|
57
|
+
npm list -link
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
#### Unlinking Projects after Local Development is Complete
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
# remove link to local files
|
|
64
|
+
npm install --save @televet/kibble-ui # re-install published project
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
#### `src` directory structure
|
|
68
|
+
|
|
69
|
+
Development takes place inside `src` directory. This is where your library code should live, this code will be bundled with rollup and published to NPM. Exports from `src/index.js` will be included in the library. Files with the `.stories.*` extension will be compiled and built to the `docs` folder and deployed with github pages.
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
|-- src # library code
|
|
73
|
+
| |-- components
|
|
74
|
+
| | |-- ComponentName # Component will be exposed as a part of library
|
|
75
|
+
| | | |-- Component.spec.js # test file
|
|
76
|
+
| | | |-- __snapshots__
|
|
77
|
+
| | | | └── Component.spec.js.snap # test snapshot
|
|
78
|
+
| | | |-- Component.stories.tsx # storybook file
|
|
79
|
+
| | | └── index.tsx
|
|
80
|
+
| |-- providers
|
|
81
|
+
| | |-- ThemeProvider
|
|
82
|
+
| |-- theme
|
|
83
|
+
| | |-- blur.ts
|
|
84
|
+
| | |-- borders.ts
|
|
85
|
+
| | |-- breakpoints.ts
|
|
86
|
+
| | |-- colors.ts
|
|
87
|
+
| | |-- fonts.ts
|
|
88
|
+
| | |-- fontSizes.ts
|
|
89
|
+
| | |-- fontWeights.ts
|
|
90
|
+
| | |-- index.ts
|
|
91
|
+
| | |-- letterSpacings.ts
|
|
92
|
+
| | |-- lineHeights.ts
|
|
93
|
+
| | |-- radii.ts
|
|
94
|
+
| | |-- shadows.ts
|
|
95
|
+
| | |-- sizes.ts
|
|
96
|
+
| | |-- space.ts
|
|
97
|
+
| | |-- transitions.ts
|
|
98
|
+
| | |-- zIndeces.ts
|
|
99
|
+
| └── index.js # entry point for rollup build
|
|
100
|
+
└── setupTests.js
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Build
|
|
104
|
+
|
|
105
|
+
Template has [Storybook](https://storybook.js.org/) configuration to handle documentation and examples.
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
npm run start # starts Storybook in development mode, http://localhost:6006/
|
|
109
|
+
npm run build # bundles library code to `build` folder, and documentation code to `docs` folder in the root of project.
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
You can view live documentation here after deploying: https://televet.github.io/kibble-ui/
|
|
113
|
+
|
|
114
|
+
## Deploy and Publish
|
|
115
|
+
|
|
116
|
+
1. Update npm version number with [one of these commands](https://docs.npmjs.com/updating-your-published-package-version-number).
|
|
117
|
+
2. Run `npm run build`
|
|
118
|
+
3. Commit changes to git.
|
|
119
|
+
4. When pushing to master, GitHub will publish the package to npm with latest changes.
|
|
120
|
+
|
|
121
|
+
This repository is using a [GitHub Worflow](https://docs.github.com/en/actions/using-workflows). See the `.github` folder for more information.
|
|
122
|
+
|
|
123
|
+
## Test
|
|
124
|
+
|
|
125
|
+
Please include tests next to the file you are testing.
|
|
126
|
+
`npm run test` - Run all tests
|
|
127
|
+
`npm run test:watch` - Watch tests
|
|
128
|
+
|
|
129
|
+
## Lint
|
|
130
|
+
|
|
131
|
+
On commit, [husky](https://github.com/typicode/husky) will run [lint-staged](https://github.com/okonet/lint-staged) with `eslint --fix` command on staged files, preventing you from committing badly formatted code. You can change or disable this behavior inside `.linstagedrc` config file. Before each push tests will run in the same manner.
|
|
132
|
+
|
|
133
|
+
### Caveats
|
|
134
|
+
|
|
135
|
+
- If pre-commit hooks not work (e. g. your code is not linted after commit), run `yarn add husky` in your project folder.
|
|
136
|
+
|
|
137
|
+
#### eslint
|
|
138
|
+
|
|
139
|
+
```shell script
|
|
140
|
+
yarn lint:js # runs eslint in src directory
|
|
141
|
+
yarn fix:js # runs eslint in src directory with --fix parameter
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Template extends [CRA eslint rules](https://github.com/facebook/create-react-app/tree/master/packages/eslint-config-react-app) with custom set, tailored for reasonable and clean development process. I added `prettier` to force consistent formatting and `eslint-plugin-fp` to avoid accidental mutations. Don't like trailing semicolons? Feel free to [tweak prettier rules](https://prettier.io/docs/en/configuration.html) inside `.prettierrc` file to match your code style.
|
|
145
|
+
|
|
146
|
+
#### stylelint
|
|
147
|
+
|
|
148
|
+
```shell script
|
|
149
|
+
yarn lint:style # runs stylelint in src directory
|
|
150
|
+
yarn fix:style # runs stylelint in src directory with --fix parameter
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Template includes [stylelint](https://stylelint.io/), to check CSS/SASS/LESS files. We are using [`stylelint-config-standard`](https://github.com/stylelint/stylelint-config-standard) rule set extended with:
|
|
154
|
+
|
|
155
|
+
```js
|
|
156
|
+
// Check `calc` functions formatting, required for `calc` to work in IE11
|
|
157
|
+
"function-calc-no-unspaced-operator": true,
|
|
158
|
+
// Custom rules (aka CSS vars) should go first
|
|
159
|
+
"order/order": [
|
|
160
|
+
"custom-properties",
|
|
161
|
+
"declarations"
|
|
162
|
+
],
|
|
163
|
+
// Require rules to be in alphabetical order
|
|
164
|
+
"order/properties-alphabetical-order": true,
|
|
165
|
+
// Disallow vendor prefixes, since CRA has autoprefixer enabled
|
|
166
|
+
"property-no-vendor-prefix": true,
|
|
167
|
+
"media-feature-name-no-vendor-prefix": true,
|
|
168
|
+
"at-rule-no-vendor-prefix": true,
|
|
169
|
+
"selector-no-vendor-prefix": true,
|
|
170
|
+
// Limit rules nesting for readablity purposes
|
|
171
|
+
"max-nesting-depth": 3,
|
|
172
|
+
// Limit selector complexity for readablity purposes
|
|
173
|
+
"selector-max-compound-selectors": 5
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Stylelint errors don't prevent build of application in development mode.
|
|
177
|
+
|
|
178
|
+
## Style options
|
|
179
|
+
|
|
180
|
+
### CSS modules
|
|
181
|
+
|
|
182
|
+
Template uses vanilla CSS with `autoprefixer` enabled. To avoid classname collisions and reduce nesting we are using `css-modules`. To make css-modules work, stylesheet file name should have `.module` suffix.
|
|
183
|
+
|
|
184
|
+
```jsx
|
|
185
|
+
import React from 'react';
|
|
186
|
+
import classes from './Component.module.css';
|
|
187
|
+
|
|
188
|
+
const Component = () => <div className={classes.wrapper}>Component</div>;
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Add SASS/SCSS
|
|
192
|
+
|
|
193
|
+
SASS/SCSS support comes "out of the box" in CRA. To enable it:
|
|
194
|
+
|
|
195
|
+
1. Install `node-sass`
|
|
196
|
+
|
|
197
|
+
```shell script
|
|
198
|
+
yarn add node-sass gatsby-plugin-sass --dev
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
2. Change `.lintstagedrc` to lint `scss` files instead of `css`.
|
|
202
|
+
|
|
203
|
+
```json
|
|
204
|
+
{
|
|
205
|
+
"*.js": ["eslint --fix"],
|
|
206
|
+
"*.scss": ["stylelint --fix"]
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
3. Change `rollup.config.js` to support `scss` files:
|
|
211
|
+
|
|
212
|
+
```js
|
|
213
|
+
postcss({
|
|
214
|
+
extract: process.env.REACT_APP_PKG_STYLE || pkg.style,
|
|
215
|
+
inline: false,
|
|
216
|
+
plugins: postcssPlugins,
|
|
217
|
+
extensions: ['scss'], // <=== here
|
|
218
|
+
}),
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
4. Add scss support to Docz. Create `gatsby-config.js` in the root of project.
|
|
222
|
+
|
|
223
|
+
```js
|
|
224
|
+
// gatsby-config.js
|
|
225
|
+
module.exports = {
|
|
226
|
+
plugins: [
|
|
227
|
+
{
|
|
228
|
+
resolve: `gatsby-plugin-sass`,
|
|
229
|
+
options: {
|
|
230
|
+
// Override the file regex for SASS
|
|
231
|
+
sassRuleTest: /\.s(a|c)ss$/,
|
|
232
|
+
// Override the file regex for CSS modules
|
|
233
|
+
sassRuleModulesTest: /\.module\.s(a|c)ss$/,
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
],
|
|
237
|
+
};
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
5. Import `scss` files straight into Component.
|
|
241
|
+
|
|
242
|
+
```jsx
|
|
243
|
+
import React from 'react';
|
|
244
|
+
import classes from './Component.module.scss'; // note the changed extension
|
|
245
|
+
|
|
246
|
+
const Component = () => <div className={classes.wrapper}>Component</div>;
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
You can see all changes required to enable SASS/SCSS in [corresponding PR](https://github.com/morewings/cra-template-npm-library/pull/11).
|
|
250
|
+
|
|
251
|
+
### Add PostCSS
|
|
252
|
+
|
|
253
|
+
1. Install `postcss-cli` and related plugins:
|
|
254
|
+
```shell script
|
|
255
|
+
yarn add --dev postcss-nested postcss-cli postcss-preset-env npm-run-all
|
|
256
|
+
```
|
|
257
|
+
2. Modify package scripts:
|
|
258
|
+
|
|
259
|
+
```json
|
|
260
|
+
{
|
|
261
|
+
"build:style": "postcss src/**/*.pcss --dir src --base src --ext css",
|
|
262
|
+
"watch:style": "yarn build:style -w",
|
|
263
|
+
"start": "npm-run-all -p watch:style start:js",
|
|
264
|
+
"start:js": "react-scripts start",
|
|
265
|
+
"build:js": "react-scripts build",
|
|
266
|
+
"build": "npm-run-all build:style build:js"
|
|
267
|
+
}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
3. Add postcss support to Docz. Create `gatsby-config.js` in the root of project.
|
|
271
|
+
|
|
272
|
+
```js
|
|
273
|
+
// gatsby-config.js
|
|
274
|
+
module.exports = {
|
|
275
|
+
plugins: [`gatsby-plugin-postcss`],
|
|
276
|
+
};
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
4. Add `postcss.config.js` file in the root folder. With following configuration:
|
|
280
|
+
|
|
281
|
+
```js
|
|
282
|
+
const pkg = require('./package.json');
|
|
283
|
+
|
|
284
|
+
module.exports = {
|
|
285
|
+
plugins: [
|
|
286
|
+
require('postcss-nested'), // handle nested selectors, like LESS or SASS
|
|
287
|
+
require('postcss-preset-env')({
|
|
288
|
+
browsers: pkg.browserslist.production, // use browsers list from production mode
|
|
289
|
+
stage: 1,
|
|
290
|
+
}),
|
|
291
|
+
],
|
|
292
|
+
};
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
5. Add rule to `.gitignore` and `.stylelintrc` to ignore all css files, since we are generating them.
|
|
296
|
+
|
|
297
|
+
#### .gitignore
|
|
298
|
+
|
|
299
|
+
```gitignore
|
|
300
|
+
# css
|
|
301
|
+
*.css
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
#### .stylelintrc
|
|
305
|
+
|
|
306
|
+
```json
|
|
307
|
+
{
|
|
308
|
+
"ignoreFiles": ["**/*.snap", "**/*.css"]
|
|
309
|
+
}
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
6. Change `.lintstagedrc` to lint `pcss` files instead of `css`.
|
|
313
|
+
|
|
314
|
+
```json
|
|
315
|
+
{
|
|
316
|
+
"*.js": ["eslint --fix"],
|
|
317
|
+
"*.pcss": ["stylelint --fix"]
|
|
318
|
+
}
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
You can see all changes required to enable PostCSS in [corresponding PR](https://github.com/morewings/cra-template-npm-library/pull/12).
|
|
322
|
+
|
|
323
|
+
### Add Less
|
|
324
|
+
|
|
325
|
+
1. Install `less` and related plugins:
|
|
326
|
+
```shell script
|
|
327
|
+
yarn add --dev less less-watch-compiler gatsby-plugin-less npm-run-all
|
|
328
|
+
```
|
|
329
|
+
2. Modify package scripts:
|
|
330
|
+
|
|
331
|
+
```json
|
|
332
|
+
{
|
|
333
|
+
"build:style": "yarn watch:style --run-once",
|
|
334
|
+
"watch:style": "less-watch-compiler src src",
|
|
335
|
+
"start": "npm-run-all -p watch:style start:js",
|
|
336
|
+
"start:js": "react-scripts start",
|
|
337
|
+
"build:js": "react-scripts build",
|
|
338
|
+
"build": "npm-run-all build:style build:js"
|
|
339
|
+
}
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
3. Add less support to Docz. Create `gatsby-config.js` in the root of project.
|
|
343
|
+
|
|
344
|
+
```js
|
|
345
|
+
// gatsby-config.js
|
|
346
|
+
module.exports = {
|
|
347
|
+
plugins: [`gatsby-plugin-less`],
|
|
348
|
+
};
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
4. Add rule to `.gitignore` and `.stylelintrc` to ignore all css files, since we are generating them.
|
|
352
|
+
|
|
353
|
+
#### .gitignore
|
|
354
|
+
|
|
355
|
+
```gitignore
|
|
356
|
+
# css
|
|
357
|
+
*.css
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
#### .stylelintrc
|
|
361
|
+
|
|
362
|
+
```json
|
|
363
|
+
{
|
|
364
|
+
"ignoreFiles": ["**/*.snap", "**/*.css"]
|
|
365
|
+
}
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
5. Change `.lintstagedrc` to lint `less` files instead of `css`.
|
|
369
|
+
|
|
370
|
+
```json
|
|
371
|
+
{
|
|
372
|
+
"*.js": ["eslint --fix"],
|
|
373
|
+
"*.less": ["stylelint --fix"]
|
|
374
|
+
}
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
You can see all changes required to enable Less in [corresponding PR](https://github.com/morewings/cra-template-npm-library/pull/10).
|
|
378
|
+
|
|
379
|
+
## Peer Dependencies
|
|
380
|
+
|
|
381
|
+
Please see below. These must be dependencies in your project to use this library
|
|
382
|
+
|
|
383
|
+
```
|
|
384
|
+
"react": ">=16.8.0",
|
|
385
|
+
"react-dom": ">=16.8.0",
|
|
386
|
+
"prop-types": ">=15.0.0"
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
## Technologies Used
|
|
390
|
+
|
|
391
|
+
- [Create React App](https://github.com/facebook/create-react-app) - (CRA) template to build and publish NPM libraries with **rollup**, **eslint** and **stylelint** configurations.
|
|
392
|
+
- [Chakra UI](https://chakra-ui.com/) - Chakra UI is a simple, modular and accessible component library that gives you the building blocks you need to build your React applications.
|
|
393
|
+
- [Styled Components](https://styled-components.com/docs) - Visual primitives for the component age.
|
|
394
|
+
- [rollup.js](https://rollupjs.org/guide/en/) - Rollup is a module bundler for JavaScript which compiles small pieces of code into something larger and more complex, such as a library or application.
|
|
395
|
+
- [Storybook](https://storybook.js.org/docs/basics/introduction/) - Build bulletproof UI components faster.
|
|
396
|
+
- [Storybook DocsPage](https://github.com/storybookjs/storybook/tree/master/addons/docs#docspage) - DocsPage pulls information from your stories, components, source code, and story metadata to construct a sensible, zero-config default.
|
|
397
|
+
- [React Testing Library](https://testing-library.com/docs/intro) - Simple and complete testing utilities that encourage good testing practices
|
package/build/index.d.ts
ADDED