@startupjs-ui/rating 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.
- package/CHANGELOG.md +20 -0
- package/README.mdx +53 -0
- package/Star/index.cssx.styl +5 -0
- package/Star/index.tsx +28 -0
- package/index.cssx.styl +8 -0
- package/index.d.ts +18 -0
- package/index.tsx +48 -0
- package/package.json +22 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## [0.1.3](https://github.com/startupjs/startupjs-ui/compare/v0.1.2...v0.1.3) (2025-12-29)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @startupjs-ui/rating
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [0.1.2](https://github.com/startupjs/startupjs-ui/compare/v0.1.1...v0.1.2) (2025-12-29)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* add mdx and docs packages. Refactor docs to get rid of any @startupjs/ui usage and use startupjs-ui instead ([703c926](https://github.com/startupjs/startupjs-ui/commit/703c92636efb0421ffd11783f692fc892b74018f))
|
|
20
|
+
* **rating:** refactor Rating component ([c820b75](https://github.com/startupjs/startupjs-ui/commit/c820b7504d01c56702d3b06833a0e45df87ee9e9))
|
package/README.mdx
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import Rating, { _PropsJsonSchema as RatingPropsJsonSchema } from './index'
|
|
3
|
+
import { Sandbox } from '@startupjs-ui/docs'
|
|
4
|
+
|
|
5
|
+
# Rating
|
|
6
|
+
|
|
7
|
+
Rating provides an ability for user to leave his opinion and view opinion of other users of a service or a product.
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import { Rating } from 'startupjs-ui'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Simple example
|
|
14
|
+
|
|
15
|
+
Rating component provides five-star rating system. The `value` prop gets rounded to the nearest integer.
|
|
16
|
+
|
|
17
|
+
```jsx example
|
|
18
|
+
return (
|
|
19
|
+
<Rating value={3} />
|
|
20
|
+
)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Controlled
|
|
24
|
+
|
|
25
|
+
```jsx example
|
|
26
|
+
const [rated, setRated] = useState(0)
|
|
27
|
+
return (
|
|
28
|
+
<Rating
|
|
29
|
+
value={rated}
|
|
30
|
+
onChange={(value) => setRated(value)}
|
|
31
|
+
/>
|
|
32
|
+
)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Read only
|
|
36
|
+
|
|
37
|
+
The `readonly` prop prevents the user from changing the value of the rating and display the it in compact view (`false` by default).
|
|
38
|
+
|
|
39
|
+
```jsx example
|
|
40
|
+
return(
|
|
41
|
+
<Rating value={4.5} readonly />
|
|
42
|
+
)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Sandbox
|
|
46
|
+
|
|
47
|
+
<Sandbox
|
|
48
|
+
Component={Rating}
|
|
49
|
+
propsJsonSchema={RatingPropsJsonSchema}
|
|
50
|
+
props={{
|
|
51
|
+
onChange: value => alert('Value ' + value + ' selected.')
|
|
52
|
+
}}
|
|
53
|
+
/>
|
package/Star/index.tsx
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type ReactNode } from 'react'
|
|
2
|
+
import { pug, observer } from 'startupjs'
|
|
3
|
+
import { themed } from '@startupjs-ui/core'
|
|
4
|
+
import Icon, { type IconProps } from '@startupjs-ui/icon'
|
|
5
|
+
import { faStar } from '@fortawesome/free-solid-svg-icons/faStar'
|
|
6
|
+
import './index.cssx.styl'
|
|
7
|
+
|
|
8
|
+
export default observer(themed('Rating', Star))
|
|
9
|
+
|
|
10
|
+
export interface StarProps {
|
|
11
|
+
/** Custom styles applied to the star icon */
|
|
12
|
+
style?: IconProps['style']
|
|
13
|
+
/** Highlight the star as active */
|
|
14
|
+
active?: boolean
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function Star ({
|
|
18
|
+
style,
|
|
19
|
+
active
|
|
20
|
+
}: StarProps): ReactNode {
|
|
21
|
+
return pug`
|
|
22
|
+
Icon.icon(
|
|
23
|
+
styleName={active}
|
|
24
|
+
style=style
|
|
25
|
+
icon=faStar
|
|
26
|
+
)
|
|
27
|
+
`
|
|
28
|
+
}
|
package/index.cssx.styl
ADDED
package/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
// DO NOT MODIFY THIS FILE - IT IS AUTOMATICALLY GENERATED ON COMMITS.
|
|
3
|
+
|
|
4
|
+
import { type StyleProp, type ViewStyle } from 'react-native';
|
|
5
|
+
import './index.cssx.styl';
|
|
6
|
+
declare const _default: import("react").ComponentType<RatingProps>;
|
|
7
|
+
export default _default;
|
|
8
|
+
export declare const _PropsJsonSchema: {};
|
|
9
|
+
export interface RatingProps {
|
|
10
|
+
/** Custom styles applied to the root view */
|
|
11
|
+
style?: StyleProp<ViewStyle>;
|
|
12
|
+
/** Rating value displayed with stars @default 0 */
|
|
13
|
+
value?: number;
|
|
14
|
+
/** Disable interactions and show compact view */
|
|
15
|
+
readonly?: boolean;
|
|
16
|
+
/** Handler called when user selects a value */
|
|
17
|
+
onChange?: (value: number) => void;
|
|
18
|
+
}
|
package/index.tsx
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type ReactNode } from 'react'
|
|
2
|
+
import { type StyleProp, type ViewStyle } from 'react-native'
|
|
3
|
+
import { pug, observer } from 'startupjs'
|
|
4
|
+
import { themed } from '@startupjs-ui/core'
|
|
5
|
+
import Div from '@startupjs-ui/div'
|
|
6
|
+
import Span from '@startupjs-ui/span'
|
|
7
|
+
import Star from './Star'
|
|
8
|
+
import './index.cssx.styl'
|
|
9
|
+
|
|
10
|
+
const AMOUNT = 5
|
|
11
|
+
const ITEMS = Array(AMOUNT).fill(null)
|
|
12
|
+
|
|
13
|
+
export default observer(themed('Rating', Rating))
|
|
14
|
+
|
|
15
|
+
export const _PropsJsonSchema = {/* RatingProps */}
|
|
16
|
+
|
|
17
|
+
export interface RatingProps {
|
|
18
|
+
/** Custom styles applied to the root view */
|
|
19
|
+
style?: StyleProp<ViewStyle>
|
|
20
|
+
/** Rating value displayed with stars @default 0 */
|
|
21
|
+
value?: number
|
|
22
|
+
/** Disable interactions and show compact view */
|
|
23
|
+
readonly?: boolean
|
|
24
|
+
/** Handler called when user selects a value */
|
|
25
|
+
onChange?: (value: number) => void
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function Rating ({
|
|
29
|
+
style,
|
|
30
|
+
value = 0,
|
|
31
|
+
readonly = false,
|
|
32
|
+
onChange
|
|
33
|
+
}: RatingProps): ReactNode {
|
|
34
|
+
return pug`
|
|
35
|
+
Div(style=style vAlign='center' row)
|
|
36
|
+
if readonly
|
|
37
|
+
Star(active)
|
|
38
|
+
Span.value(bold h6)= value.toFixed(1)
|
|
39
|
+
else
|
|
40
|
+
each ITEM, index in ITEMS
|
|
41
|
+
Div.star(
|
|
42
|
+
key=index
|
|
43
|
+
onPress=() => onChange && onChange(index + 1)
|
|
44
|
+
styleName={first: index === 0}
|
|
45
|
+
)
|
|
46
|
+
Star(active=index < Math.round(value))
|
|
47
|
+
`
|
|
48
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@startupjs-ui/rating",
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"main": "index.tsx",
|
|
8
|
+
"types": "index.d.ts",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@startupjs-ui/core": "^0.1.3",
|
|
12
|
+
"@startupjs-ui/div": "^0.1.3",
|
|
13
|
+
"@startupjs-ui/icon": "^0.1.3",
|
|
14
|
+
"@startupjs-ui/span": "^0.1.3"
|
|
15
|
+
},
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"react": "*",
|
|
18
|
+
"react-native": "*",
|
|
19
|
+
"startupjs": "*"
|
|
20
|
+
},
|
|
21
|
+
"gitHead": "fd964ebc3892d3dd0a6c85438c0af619cc50c3f0"
|
|
22
|
+
}
|