ranui 0.1.2 → 0.1.3

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.
Files changed (2) hide show
  1. package/package.json +11 -11
  2. package/readme.md +102 -17
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ranui",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "UI Component library based on `Web Component`",
5
5
  "main": "dist/index.umd.cjs",
6
6
  "module": "dist/index.js",
@@ -24,14 +24,6 @@
24
24
  "type": "git",
25
25
  "url": "git+https://github.com/chaxus/ran/tree/main/packages/ranui"
26
26
  },
27
- "scripts": {
28
- "dev": "vite",
29
- "build": "vite build",
30
- "prepublish": "npm run build",
31
- "test": "sh ./bin/test.sh",
32
- "test:report": "playwright show-report",
33
- "test:ui": "playwright test --ui"
34
- },
35
27
  "keywords": [
36
28
  "ran",
37
29
  "component",
@@ -50,7 +42,7 @@
50
42
  "@types/tinycolor2": "^1.4.3",
51
43
  "less": "^4.1.3",
52
44
  "prettier": "^2.8.1",
53
- "ranuts": "workspace:0.1.0-alpha.7",
45
+ "ranuts": "0.1.0-alpha.7",
54
46
  "svgo": "^3.0.0",
55
47
  "vite": "^4.4.9",
56
48
  "vite-plugin-dts": "^3.5.2"
@@ -63,5 +55,13 @@
63
55
  "lodash": "^4.17.21",
64
56
  "tinycolor2": "^1.6.0",
65
57
  "x-data-spreadsheet": "^1.1.9"
58
+ },
59
+ "scripts": {
60
+ "dev": "vite",
61
+ "build": "vite build",
62
+ "prepublish": "npm run build",
63
+ "test": "sh ./bin/test.sh",
64
+ "test:report": "playwright show-report",
65
+ "test:ui": "playwright test --ui"
66
66
  }
67
- }
67
+ }
package/readme.md CHANGED
@@ -12,9 +12,9 @@ UI Component library based on `Web Component`
12
12
 
13
13
  ## Feature
14
14
 
15
- - **Across the frame**: It works with react, vue, or native projects.
16
- - **Componentization**: The shadow dom actually implements componentization of style and functionality.
17
- - **native**: A component is like using a div tag.
15
+ - **Across the frame**: It works with `react`, `vue`, or native projects.
16
+ - **Componentization**: The `shadow dom` actually implements componentization of style and functionality.
17
+ - **native**: A component is like using a `div`tag.
18
18
 
19
19
  ## Install
20
20
 
@@ -32,21 +32,17 @@ npm install ranui --save
32
32
 
33
33
  It is based on the `Web Component`, you can use it without focusing on the framework.
34
34
 
35
- - tsx
36
-
37
- ```tsx
38
- import Button from 'ranui'
35
+ In most cases, you can use it just like a native `div` tag
39
36
 
40
- const App = () => {
41
- return (
42
- <>
43
- <r-button>Button</r-button>
44
- </>
45
- )
46
- }
47
- ```
37
+ Here are some examples:
48
38
 
49
39
  - html
40
+ - js
41
+ - jsx
42
+ - vue
43
+ - tsx
44
+
45
+ ### html
50
46
 
51
47
  ```html
52
48
  <script src="./ranui/dist/index.umd.cjs"></script>
@@ -56,7 +52,7 @@ const App = () => {
56
52
  </body>
57
53
  ```
58
54
 
59
- - js
55
+ ### js
60
56
 
61
57
  ```js
62
58
  import 'ranui'
@@ -66,6 +62,95 @@ Button.appendChild('this is button text')
66
62
  document.body.appendChild(Button)
67
63
  ```
68
64
 
69
- ### Meta
65
+ ### jsx
66
+
67
+ ```jsx
68
+ import 'ranui'
69
+ const App = () => {
70
+ return (
71
+ <>
72
+ <r-button>Button</r-button>
73
+ </>
74
+ )
75
+ }
76
+ ```
77
+
78
+ ### vue
79
+
80
+ ```vue
81
+ <template>
82
+ <r-button></r-button>
83
+ </template>
84
+ <script>
85
+ import 'ranui'
86
+ </script>
87
+
88
+ ```
89
+
90
+ ### tsx
91
+
92
+ ```tsx
93
+ // react 18
94
+ import type { SyntheticEvent } from 'react';
95
+ import React, { useRef } from 'react'
96
+ import 'ranui'
97
+
98
+ const FilePreview = () => {
99
+ const ref = useRef<HTMLDivElement | null>(null)
100
+ const uploadFile = (e: SyntheticEvent<HTMLDivElement>) => {
101
+ if (ref.current) {
102
+ const uploadFile = document.createElement('input')
103
+ uploadFile.setAttribute('type', 'file')
104
+ uploadFile.click()
105
+ uploadFile.onchange = (e) => {
106
+ const { files = [] } = uploadFile
107
+ if (files && files?.length > 0 && ref.current) {
108
+ ref.current.setAttribute('src', '')
109
+ const file = files[0]
110
+ const url = URL.createObjectURL(file)
111
+ ref.current.setAttribute('src', url)
112
+ }
113
+ }
114
+ }
115
+ }
116
+ return (
117
+ <div >
118
+ <r-preview ref={ref}></r-preview>
119
+ <r-button type="primary" onClick={uploadFile}>choose file to preview</r-button>
120
+ </div>
121
+ )
122
+ }
123
+ ```
124
+
125
+ `jsx` defines the types of all `HTML-native` components in `TypeScript`.
126
+
127
+ The `web component` type is not in the `jsx` definition.
128
+
129
+ You need to add it manually.
130
+
131
+ Otherwise you'll have type problems, but it actually works.
132
+
133
+ ```ts
134
+ // typings.d.ts
135
+ interface RButton {
136
+ type?: string,
137
+ onClick?: React.MouseEventHandler<HTMLDivElement> | undefined
138
+ }
139
+
140
+ interface RPreview {
141
+ src?: string | Blob | ArrayBuffer,
142
+ onClick?: React.MouseEventHandler<HTMLDivElement> | undefined
143
+ ref?: React.MutableRefObject<HTMLDivElement | null>
144
+ }
145
+
146
+ declare namespace JSX {
147
+ interface IntrinsicElements {
148
+ 'r-preview': React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> & RPreview
149
+ 'r-button': React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> & RButton
150
+ }
151
+ }
152
+ ```
153
+
154
+ ## Meta
70
155
 
71
156
  [LICENSE (MIT)](/LICENSE)