sprintify-ui 0.0.0 → 0.0.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 +47 -158
- package/dist/sprintify-ui.es.js +2239 -0
- package/dist/style.css +4 -0
- package/dist/types/src/components/BaseAutocomplete.vue.d.ts +4 -4
- package/dist/types/src/components/index.d.ts +4 -1
- package/dist/types/src/index.d.ts +2 -1
- package/package.json +3 -2
- package/src/assets/main.css +1 -1
- package/src/components/BaseAutocomplete.vue +1 -1
- package/src/components/BaseBelongsTo.vue +1 -1
- package/src/components/BaseDataIterator.vue +1 -1
- package/src/components/BaseDataTable.vue +9 -9
- package/src/components/BaseDatePicker.vue +1 -1
- package/src/components/BaseFileUploader.vue +7 -7
- package/src/components/BaseMediaLibrary.vue +11 -10
- package/src/components/BaseTagAutocomplete.vue +4 -4
- package/src/components/BaseTagAutocompleteFetch.vue +1 -1
- package/src/components/index.ts +5 -4
- package/src/index.ts +8 -6
- package/src/utils/fileSizeFormat.ts +1 -1
- package/src/utils/toHumanList.ts +1 -1
package/README.md
CHANGED
|
@@ -1,188 +1,77 @@
|
|
|
1
|
-
|
|
1
|
+
## Peer dependencies:
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
vue
|
|
4
|
+
vue-18n
|
|
5
|
+
vue-router
|
|
6
|
+
pinia
|
|
4
7
|
|
|
5
|
-
|
|
8
|
+
They must all be installed and configured with your vue app.
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
## Install
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
```ts
|
|
13
|
+
import SprintifyUI from "sprintify-ui";
|
|
10
14
|
|
|
11
|
-
|
|
15
|
+
// Import your tailwind.css *before* importing Sprintify UI CSS
|
|
16
|
+
import "../css/tailwind.css";
|
|
12
17
|
|
|
13
|
-
|
|
18
|
+
// Import Sprintify UI CSS
|
|
19
|
+
import "sprintify-ui/dist/style.css";
|
|
14
20
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
# start the doc app with hot reload, great for testing components
|
|
20
|
-
npm run docs:dev
|
|
21
|
-
|
|
22
|
-
# build the library, available under dist
|
|
23
|
-
npm run build
|
|
24
|
-
|
|
25
|
-
# build the doc app, available under docs/.vitepress/dist
|
|
26
|
-
npm run docs:build
|
|
27
|
-
|
|
28
|
-
# preview the doc app locally from docs/.vitepress/dist
|
|
29
|
-
npm run docs:serve
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
You may use [Netlify](https://www.netlify.com/) to auto build and deloy the doc app like this project does.
|
|
33
|
-
|
|
34
|
-
## Develop and test locally
|
|
35
|
-
|
|
36
|
-
The best way to develop and test your component is by creating demos in `docs/components/demo` folder, as shown by the example components.
|
|
37
|
-
|
|
38
|
-
If you want to test the library in your Vue3 app locally:
|
|
39
|
-
|
|
40
|
-
- In the root folder of this library, run `npm link`. This will create a symbolic link to the library.
|
|
41
|
-
- In the root folder of your client app, run `npm link sprintify-ui`. This will add the symbolic link to the `node_modules` folder in your client app.
|
|
42
|
-
- You can now import `sprintify-ui` in your client app.
|
|
43
|
-
|
|
44
|
-
There is no need to add `sprintify-ui` to your client app's dependency in this case.
|
|
45
|
-
|
|
46
|
-
If you made changes to the library, you will need to rebuild the library. Your Vue3 app shall hot reload when the building of library is completed.
|
|
47
|
-
|
|
48
|
-
## How it works
|
|
49
|
-
|
|
50
|
-
### Components
|
|
51
|
-
|
|
52
|
-
The library is a [Vue plugin](https://v3.vuejs.org/guide/plugins.html). The `install` function in [index.ts](src/index.ts) registers all components under [components](src/components) to Vue globably.
|
|
53
|
-
|
|
54
|
-
The components are also exported by [index.ts](src/index.ts) so that the client app can import them individually and register them locally, instead of using the library as a plugin. This may be a better option if the client app only use a small set of components in your library.
|
|
55
|
-
|
|
56
|
-
As there are already many UI component libraries for Vue 3, you may just want to build on top of one of them and create components for your specific needs. The Component B in this starter shows the example of using [PrimeVue](https://www.primefaces.org/primevue/) as the fundation library. However, this means the client app shall also use the same fundation component library as your library does.
|
|
57
|
-
|
|
58
|
-
The doc app itself is a client app of the libary, therefore PrimeVue is imported in [docs/.vitepress/theme/index.js](docs/.vitepress/theme/index.js). The configuration in [docs/.vitepress/config.js](docs/.vitepress/config.js) below forces VitePress to resolve these modules with no duplication, avoiding error at runtime, as PrimeVue also has Vue in its dependency.
|
|
59
|
-
|
|
60
|
-
```js
|
|
61
|
-
module.exports = {
|
|
62
|
-
vite: {
|
|
63
|
-
resolve: {
|
|
64
|
-
dedupe: ['vue', /primevue\/.+/],
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
}
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
> In [vite.config.ts](vite.config.ts), format 'umd' is not present in `build.lib.formats` option. This is because the PrimeVue components used by this library are externalized, and therefore requiring corresponding options in `rollupOptions.output.globals`. To avoid adding global varaibles for PrimeVue components, 'umd' is removed for simplicity.
|
|
71
|
-
|
|
72
|
-
### Utilities and constants
|
|
73
|
-
|
|
74
|
-
The library includes example utilities and constants. They are also exported in [index.ts](src/index.ts). The client app may use them as below:
|
|
75
|
-
|
|
76
|
-
```js
|
|
77
|
-
<script lang="ts">
|
|
78
|
-
import { MyConstants, MyUtil } from 'sprintify-ui'
|
|
79
|
-
|
|
80
|
-
export default {
|
|
81
|
-
data () {
|
|
82
|
-
return {
|
|
83
|
-
magicNum: MyConstants.MAGIC_NUM
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
methods: {
|
|
87
|
-
add (a:number, b:number) {
|
|
88
|
-
return MyUtil.add(a, b)
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
</script>
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
### Styling
|
|
96
|
-
|
|
97
|
-
Individual compopnent may have styles defined in its `.vue` file. They will be processed, combined and minified into `dist/style.css`, which is included in the `exports` list in [package.json](package.json).
|
|
98
|
-
|
|
99
|
-
If you have library level styles shared by all components in the library, you may add them to [src/assets/main.scss](src/assets/main.scss). This file is imported in [index.ts](src/index.ts), therefore the processed styles are also included into `dist/style.css`. To avoid conflicting with other global styles, consider pre-fixing the class names or wrapping them into a namespace class.
|
|
21
|
+
// Import router and i18n *before* importing Sprintify UI plugin
|
|
22
|
+
app.use(router);
|
|
23
|
+
app.use(i18n);
|
|
100
24
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
The client app shall import `style.css`, usually in the entry file:
|
|
104
|
-
|
|
105
|
-
```js
|
|
106
|
-
import 'sprintify-ui/dist/style.css'
|
|
25
|
+
// Import Sprintify UI plugin
|
|
26
|
+
app.use(SprintifyUI);
|
|
107
27
|
```
|
|
108
28
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
Third-party libraries used by you library may bloat up the size of your library, if you simply add them to the `dependencies` in [package.json](package.json).
|
|
29
|
+
## i18n
|
|
112
30
|
|
|
113
|
-
|
|
31
|
+
Add Sprintify UI messages :
|
|
114
32
|
|
|
115
|
-
|
|
33
|
+
```ts
|
|
116
34
|
|
|
117
|
-
|
|
35
|
+
import en from "sprintify-ui/dist/lang/en.json";
|
|
36
|
+
import fr from "sprintify-ui/dist/lang/fr.json";
|
|
118
37
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
})
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
The dependency to be externalized may be declared as peer dependency in your library.
|
|
38
|
+
const messages = {
|
|
39
|
+
en: {},
|
|
40
|
+
fr: {},
|
|
41
|
+
};
|
|
129
42
|
|
|
130
|
-
|
|
43
|
+
messages.en.sui = en.sui;
|
|
44
|
+
messages.fr.sui = fr.sui;
|
|
131
45
|
|
|
132
|
-
|
|
46
|
+
const i18n = createI18n({
|
|
47
|
+
locale: "en",
|
|
48
|
+
messages,
|
|
49
|
+
});
|
|
133
50
|
|
|
134
|
-
```js
|
|
135
|
-
import fill from 'lodash/fill'
|
|
136
51
|
```
|
|
137
52
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
Note that `import { fill } from 'lodash'` or `import _ from 'lodash'` will not work and will embed the whole `lodash` library.
|
|
141
|
-
|
|
142
|
-
Finally, if your client app also use `lodash` and you don't want `lodash` to be in both the client app and your libraries, even after cherry-picking, you may consider cherry-picking in component library and re-export them as utils for client to consume, so that the client does not need to depend on `lodash`, therefore avoiding duplication.
|
|
53
|
+
## Tailwindcss
|
|
143
54
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
In [tsconfig.json](tsconfig.json), the following options instructs `tsc` to emit declaration (`.d.ts` files) only, as `vite build` handles the `.js` file generation. The generated `.d.ts` files are sent to `dist/types` folder.
|
|
55
|
+
Update your tailwind.config.json:
|
|
147
56
|
|
|
148
57
|
```json
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
58
|
+
{
|
|
59
|
+
content: [
|
|
60
|
+
//...,
|
|
61
|
+
"./node_modules/sprintify-ui/src/**/*.ts",
|
|
62
|
+
"./node_modules/sprintify-ui/src/**/*.js",
|
|
63
|
+
"./node_modules/sprintify-ui/src/**/*.vue",
|
|
64
|
+
]
|
|
153
65
|
}
|
|
154
66
|
```
|
|
155
67
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
```json
|
|
159
|
-
"types": "./dist/types/index.d.ts",
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
> In [vite.config.ts](vite.config.ts), `build.emptyOutDir` is set to `false` and `rimraf` is used instead to remove the `dist` folder before the build. This is to avoid the `dist/types` folder generated by `tsc` being deleted when running `vite build`.
|
|
163
|
-
|
|
164
|
-
### Configuration
|
|
68
|
+
Make sure you have all the required plugins installed:
|
|
165
69
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
In [tsconfig.json](tsconfig.js), set the following as recommended by Vite (since esbuild is used). However, enableing this option leads to https://github.com/vitejs/vite/issues/5814. The workaround is to also enable `compilerOptions.skipLibCheck`.
|
|
169
|
-
|
|
170
|
-
```json
|
|
171
|
-
"compilerOptions": {
|
|
172
|
-
"isolatedModules": true
|
|
173
|
-
}
|
|
70
|
+
```bash
|
|
71
|
+
npm i tailwindcss @tailwindcss/forms @tailwindcss/typography @tailwindcss/aspect-ratio @tailwindcss/line-clamp -D
|
|
174
72
|
```
|
|
175
73
|
|
|
176
|
-
In [tsconfig.json](tsconfig.js), set the following to address [Issue #32](https://github.com/wuruoyun/vue-component-lib-starter/issues/32). The solution is from https://github.com/johnsoncodehk/volar/discussions/592.
|
|
177
|
-
|
|
178
|
-
```json
|
|
179
|
-
"compilerOptions": {
|
|
180
|
-
"types": [
|
|
181
|
-
"vite/client"
|
|
182
|
-
]
|
|
183
|
-
}
|
|
184
|
-
```
|
|
185
74
|
|
|
186
|
-
|
|
75
|
+
TODO change Icon to BaseIcon
|
|
76
|
+
TODO explain how to configure vite components plugin
|
|
187
77
|
|
|
188
|
-
In [package.json](package.json), Vue and PrimeVue are declared in both `peerDependencies` and `devDependencies`. The former requires the client app to add these dependencies, and the later makes it easier to setup this library by simply running `npm install`.
|