@startupjs-ui/badge 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 ADDED
@@ -0,0 +1,21 @@
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/badge
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
+ * **badge:** refactor Badge component ([91b1b06](https://github.com/startupjs/startupjs-ui/commit/91b1b0623dc14358ad037a607f261289e1a8af9e))
21
+ * **menu:** refactor Menu component. Fix useColors types. ([ffd4671](https://github.com/startupjs/startupjs-ui/commit/ffd46719c308f99d856d8020ebfc070bb479ab28))
package/README.mdx ADDED
@@ -0,0 +1,127 @@
1
+ import Badge, { _PropsJsonSchema as BadgePropsJsonSchema } from './index'
2
+ import Div from '@startupjs-ui/div'
3
+ import Icon from '@startupjs-ui/icon'
4
+ import { faThumbsUp, faEnvelope } from '@fortawesome/free-solid-svg-icons'
5
+ import { Sandbox } from '@startupjs-ui/docs'
6
+
7
+ # Badge
8
+
9
+ Badge is small state descriptors for UI elements.
10
+
11
+ ```js
12
+ import { Badge } from 'startupjs-ui'
13
+ ```
14
+
15
+ ## Simple example
16
+
17
+ ```jsx example
18
+ return (
19
+ <Badge label='10'>
20
+ <Icon icon={faEnvelope} size={40} />
21
+ </Badge>
22
+ )
23
+ ```
24
+
25
+ ## Sizes
26
+
27
+ Badges come in three different sizes: `s`, `m`, and `l`. The `m` size is the default and most frequently used. The other sizes should be used with care so as not to break the hierarchy of importance on the page.
28
+
29
+ ```jsx example
30
+ return (
31
+ <Div row>
32
+ <Badge label='16' size='s'>
33
+ <Icon icon={faEnvelope} size={40} />
34
+ </Badge>
35
+ <Badge style={{ marginLeft: 16 }} label='20'>
36
+ <Icon icon={faEnvelope} size={40} />
37
+ </Badge>
38
+ <Badge style={{ marginLeft: 16 }} label='24' size='l'>
39
+ <Icon icon={faEnvelope} size={40} />
40
+ </Badge>
41
+ </Div>
42
+ )
43
+ ```
44
+
45
+ ## Variants
46
+
47
+ There are two types of Badges: `default` and `dot`. `default` it is the most frequently used and the default specified. `dot` turns the badge into a small dot, this can be used as a message that something has changed. If the property is `variant='dot'`, the `size` property will be ignored.
48
+
49
+ ```jsx example
50
+ return (
51
+ <Div row>
52
+ <Badge label='10'>
53
+ <Icon icon={faEnvelope} size={40} />
54
+ </Badge>
55
+ <Badge style={{ marginLeft: 16 }} variant='dot'>
56
+ <Icon icon={faEnvelope} size={40} />
57
+ </Badge>
58
+ </Div>
59
+ )
60
+ ```
61
+
62
+ ## Colors
63
+
64
+ Color is `primary` by default. It can be changed by passing color name from the config colors to `color` property. Possible values of property can be found in the `Sandbox` section at the bottom of the page.
65
+
66
+ ```jsx example
67
+ return (
68
+ <Badge color='error' label='10'>
69
+ <Icon icon={faEnvelope} size={40}/>
70
+ </Badge>
71
+ )
72
+ ```
73
+
74
+ ## Position
75
+
76
+ Badge can be in two positions: `top` and `bottom`. **Default value:** `top`.
77
+
78
+ ```jsx example
79
+ return (
80
+ <Div row>
81
+ <Badge label='10'>
82
+ <Icon icon={faEnvelope} size={40} />
83
+ </Badge>
84
+ <Badge style={{ marginLeft: 16 }} position='bottom' label='10'>
85
+ <Icon icon={faEnvelope} size={40} />
86
+ </Badge>
87
+ </Div>
88
+ )
89
+ ```
90
+
91
+ ## Icons
92
+
93
+ Icon can be added using `icon` property.
94
+
95
+ ```jsx example
96
+ return (
97
+ <Badge icon={faThumbsUp} label='10+' color='success'>
98
+ <Icon icon={faEnvelope} size={40} />
99
+ </Badge>
100
+ )
101
+ ```
102
+
103
+ ## Counter
104
+
105
+ If `label` property takes a numeric value, then the `max` property can be used to limit the maximum displayed number in the label.
106
+
107
+ ```jsx example
108
+ return (
109
+ <Badge label={1000} max={100}>
110
+ <Icon icon={faEnvelope} size={40} />
111
+ </Badge>
112
+ )
113
+ ```
114
+
115
+ ## Sandbox
116
+
117
+ <Sandbox
118
+ Component={Badge}
119
+ propsJsonSchema={BadgePropsJsonSchema}
120
+ extraParams={{
121
+ icon: {
122
+ showIconSelect: true
123
+ }
124
+ }}
125
+ props={{ children: <Icon icon={faEnvelope} size={40} />, label: 100 }}
126
+ noScroll
127
+ />
@@ -0,0 +1,57 @@
1
+ _sizes = {
2
+ s: 2u,
3
+ m: 2.5u,
4
+ l: 3u,
5
+ dot: 1u
6
+ }
7
+
8
+ .root
9
+ position relative
10
+ align-self flex-start
11
+
12
+ .badge
13
+ position absolute
14
+ justify-content center
15
+ align-items center
16
+ border-width 1px
17
+ border-color var(--color-border-main-strong)
18
+ opacity 0
19
+
20
+ &.visible
21
+ opacity 1
22
+
23
+ for size, unit in _sizes
24
+ _halfSize = unit / 2
25
+
26
+ &.{size}
27
+ min-width unit
28
+ height unit
29
+ border-radius _halfSize
30
+
31
+ &.top
32
+ top -(_halfSize)
33
+ &.bottom
34
+ bottom -(_halfSize)
35
+
36
+ &.hasLabel
37
+ &.s
38
+ &.m
39
+ padding 0 0.5u
40
+ &.l
41
+ padding 0 1u
42
+
43
+ .label
44
+ &.s
45
+ font-size 1.25u
46
+ line-height 1.5u
47
+
48
+ &.m
49
+ font-size 1.5u
50
+ line-height 2u
51
+
52
+ &.l
53
+ font-size 2u
54
+ line-height 2.5u
55
+
56
+ &.icon
57
+ margin-left 0.25u
package/index.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ /* eslint-disable */
2
+ // DO NOT MODIFY THIS FILE - IT IS AUTOMATICALLY GENERATED ON COMMITS.
3
+
4
+ import { type ReactNode } from 'react';
5
+ import { type StyleProp, type ViewStyle } from 'react-native';
6
+ import './index.cssx.styl';
7
+ declare const _default: import("react").ComponentType<BadgeProps>;
8
+ export default _default;
9
+ export declare const _PropsJsonSchema: {};
10
+ export interface BadgeProps {
11
+ /** Custom styles applied to the root view */
12
+ style?: StyleProp<ViewStyle>;
13
+ /** Custom styles applied to the badge view */
14
+ badgeStyle?: StyleProp<ViewStyle>;
15
+ /** Content rendered inside Badge */
16
+ children?: ReactNode;
17
+ /** Background color name @default 'primary' */
18
+ color?: string;
19
+ /** Label content rendered inside badge */
20
+ label?: string | number;
21
+ /** Icon displayed inside badge */
22
+ icon?: object;
23
+ /** Badge vertical position @default 'top' */
24
+ position?: 'top' | 'bottom';
25
+ /** Badge size preset @default 'm' */
26
+ size?: 's' | 'm' | 'l';
27
+ /** Badge appearance variant @default 'default' */
28
+ variant?: 'default' | 'dot';
29
+ /** Maximum number to display before adding "+" */
30
+ max?: number;
31
+ }
package/index.tsx ADDED
@@ -0,0 +1,106 @@
1
+ import { useMemo, useState, type ReactNode } from 'react'
2
+ import { StyleSheet, type StyleProp, type ViewStyle } from 'react-native'
3
+ import { pug, observer } from 'startupjs'
4
+ import { Colors, themed, useColors } from '@startupjs-ui/core'
5
+ import Div from '@startupjs-ui/div'
6
+ import Icon from '@startupjs-ui/icon'
7
+ import Span from '@startupjs-ui/span'
8
+ import './index.cssx.styl'
9
+
10
+ const ICON_SIZES = {
11
+ s: 'xs',
12
+ m: 's',
13
+ l: 'm'
14
+ }
15
+
16
+ export default observer(themed('Badge', Badge))
17
+
18
+ export const _PropsJsonSchema = {/* BadgeProps */}
19
+
20
+ export interface BadgeProps {
21
+ /** Custom styles applied to the root view */
22
+ style?: StyleProp<ViewStyle>
23
+ /** Custom styles applied to the badge view */
24
+ badgeStyle?: StyleProp<ViewStyle>
25
+ /** Content rendered inside Badge */
26
+ children?: ReactNode
27
+ /** Background color name @default 'primary' */
28
+ color?: string
29
+ /** Label content rendered inside badge */
30
+ label?: string | number
31
+ /** Icon displayed inside badge */
32
+ icon?: object
33
+ /** Badge vertical position @default 'top' */
34
+ position?: 'top' | 'bottom'
35
+ /** Badge size preset @default 'm' */
36
+ size?: 's' | 'm' | 'l'
37
+ /** Badge appearance variant @default 'default' */
38
+ variant?: 'default' | 'dot'
39
+ /** Maximum number to display before adding "+" */
40
+ max?: number
41
+ }
42
+
43
+ function Badge ({
44
+ style,
45
+ badgeStyle,
46
+ children,
47
+ color = Colors.primary,
48
+ label,
49
+ icon,
50
+ position = 'top',
51
+ size = 'm',
52
+ variant = 'default',
53
+ max
54
+ }: BadgeProps): ReactNode {
55
+ const [right, setRight] = useState(0)
56
+ const getColor = useColors()
57
+
58
+ badgeStyle = StyleSheet.flatten([
59
+ { right, backgroundColor: getColor(color) },
60
+ badgeStyle
61
+ ]) as StyleProp<ViewStyle>
62
+
63
+ const textAndIconColor = getColor(`text-on-${color}`) ?? getColor('text-on-color')
64
+
65
+ const hasLabel = useMemo(() => {
66
+ return variant === 'default'
67
+ ? typeof label === 'string'
68
+ ? +label !== 0
69
+ : !!label
70
+ : false
71
+ }, [variant, label])
72
+
73
+ function getLabel (label: any, max?: number) {
74
+ return max && label > max ? max + '+' : label
75
+ }
76
+
77
+ function onLayout (event: any) {
78
+ const { width } = event.nativeEvent.layout
79
+ setRight(Math.ceil(width / 2) * -1)
80
+ }
81
+
82
+ return pug`
83
+ Div.root(style=style)
84
+ = children
85
+ if hasLabel || variant === 'dot'
86
+ Div.badge(
87
+ row
88
+ style=badgeStyle
89
+ onLayout=onLayout
90
+ styleName=[
91
+ size,
92
+ variant,
93
+ position,
94
+ { hasLabel, visible: !!right }
95
+ ]
96
+ )
97
+ if variant === 'default'
98
+ if icon
99
+ Icon(
100
+ style={ color: textAndIconColor }
101
+ icon=icon
102
+ size=ICON_SIZES[size]
103
+ )
104
+ Span.label(style={ color: textAndIconColor } styleName=[size, { icon }])= getLabel(label, max)
105
+ `
106
+ }
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@startupjs-ui/badge",
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
+ }