@startupjs-ui/item 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 +100 -0
- package/index.cssx.styl +18 -0
- package/index.d.ts +43 -0
- package/index.tsx +163 -0
- package/package.json +23 -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/item
|
|
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
|
+
* **item:** refactor Item component ([a0ed18a](https://github.com/startupjs/startupjs-ui/commit/a0ed18aaca510446fbdad771a4f6418acc1aa63f))
|
package/README.mdx
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { pug } from 'startupjs'
|
|
2
|
+
import { Image } from 'react-native'
|
|
3
|
+
import { u } from 'startupjs'
|
|
4
|
+
import Icon from '@startupjs-ui/icon'
|
|
5
|
+
import Item, { _PropsJsonSchema as ItemPropsJsonSchema } from './index'
|
|
6
|
+
import Span from '@startupjs-ui/span'
|
|
7
|
+
import { faTrashAlt, faShareAlt } from '@fortawesome/free-solid-svg-icons'
|
|
8
|
+
import { Sandbox } from '@startupjs-ui/docs'
|
|
9
|
+
|
|
10
|
+
# Item
|
|
11
|
+
|
|
12
|
+
Item is a basic component that is a wrapper over the content with the ability to position it and the ability to display an icon or image.
|
|
13
|
+
|
|
14
|
+
```jsx
|
|
15
|
+
import { Item } from 'startupjs-ui'
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Simple example
|
|
19
|
+
|
|
20
|
+
```jsx example
|
|
21
|
+
return pug`
|
|
22
|
+
Item Example
|
|
23
|
+
`
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Icon
|
|
27
|
+
|
|
28
|
+
The icon can be added using the `icon` property, which will be displayed on the left side of the component.
|
|
29
|
+
|
|
30
|
+
```jsx example
|
|
31
|
+
return pug`
|
|
32
|
+
Item(icon=faTrashAlt) Icon
|
|
33
|
+
`
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Image
|
|
37
|
+
|
|
38
|
+
The image can be added using the `url` property, which will be displayed on the left side of the component. The `url` property takes precedence over the `icon` property if both are passed.
|
|
39
|
+
|
|
40
|
+
```jsx example
|
|
41
|
+
return pug`
|
|
42
|
+
Item(url="https://i.pinimg.com/736x/95/30/41/953041070f000d45c05c912005f63724.jpg") Image
|
|
43
|
+
`
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Item as link
|
|
47
|
+
|
|
48
|
+
By passing the url to the `to` property, the component will behave like a link.
|
|
49
|
+
|
|
50
|
+
```jsx example
|
|
51
|
+
return pug`
|
|
52
|
+
Item(to='/docs/Icon') Icon component
|
|
53
|
+
`
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Actions
|
|
57
|
+
|
|
58
|
+
Passed handler to `onPress` property will be called when the user taps the component.
|
|
59
|
+
|
|
60
|
+
```jsx example
|
|
61
|
+
return pug`
|
|
62
|
+
Item(onPress=()=> alert('click')) Click me
|
|
63
|
+
`
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Advanced usage
|
|
67
|
+
|
|
68
|
+
Item consists of three parts - `Left`, `Content` and `Right`. These parts can be used to add custom markup, where:
|
|
69
|
+
|
|
70
|
+
- `Left` part is used instead of `icon` and `url` properties and inserts its content into the left side of the component.
|
|
71
|
+
|
|
72
|
+
- `Content` part is used instead of `children` and inserts its content between `Left` and `Right` parts.
|
|
73
|
+
|
|
74
|
+
- `Right` part inserts its content into the right side of the component.
|
|
75
|
+
|
|
76
|
+
```jsx example
|
|
77
|
+
return pug`
|
|
78
|
+
Item(onPress=()=> alert('click'))
|
|
79
|
+
Item.Left
|
|
80
|
+
Image(
|
|
81
|
+
style={ width: u(3), height: u(3) }
|
|
82
|
+
source={ uri: 'https://i.pinimg.com/736x/95/30/41/953041070f000d45c05c912005f63724.jpg' }
|
|
83
|
+
)
|
|
84
|
+
Item.Content
|
|
85
|
+
Span Content
|
|
86
|
+
Item.Right
|
|
87
|
+
Icon(icon=faShareAlt)
|
|
88
|
+
`
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Sandbox
|
|
92
|
+
|
|
93
|
+
<Sandbox
|
|
94
|
+
Component={Item}
|
|
95
|
+
propsJsonSchema={ItemPropsJsonSchema}
|
|
96
|
+
props={{
|
|
97
|
+
children: 'Item',
|
|
98
|
+
icon: faTrashAlt
|
|
99
|
+
}}
|
|
100
|
+
/>
|
package/index.cssx.styl
ADDED
package/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
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 { type DivProps } from '@startupjs-ui/div';
|
|
7
|
+
import { type IconProps } from '@startupjs-ui/icon';
|
|
8
|
+
import './index.cssx.styl';
|
|
9
|
+
export declare const _PropsJsonSchema: {};
|
|
10
|
+
export interface ItemProps extends Omit<DivProps, 'style' | 'onPress'> {
|
|
11
|
+
/** Custom styles applied to the root view */
|
|
12
|
+
style?: StyleProp<ViewStyle>;
|
|
13
|
+
/** Content rendered inside Item */
|
|
14
|
+
children?: ReactNode;
|
|
15
|
+
/** Navigation target passed to Link wrapper */
|
|
16
|
+
to?: string;
|
|
17
|
+
/** Image URL displayed on the left side */
|
|
18
|
+
url?: string;
|
|
19
|
+
/** Icon displayed on the left side when no image is provided */
|
|
20
|
+
icon?: IconProps['icon'];
|
|
21
|
+
/** onPress handler */
|
|
22
|
+
onPress?: (event: any) => void;
|
|
23
|
+
}
|
|
24
|
+
export interface ItemLeftProps {
|
|
25
|
+
/** Custom styles applied to the left part */
|
|
26
|
+
style?: StyleProp<ViewStyle>;
|
|
27
|
+
/** Content rendered inside left part */
|
|
28
|
+
children?: ReactNode;
|
|
29
|
+
}
|
|
30
|
+
export interface ItemContentProps {
|
|
31
|
+
/** Custom styles applied to the content wrapper */
|
|
32
|
+
style?: StyleProp<ViewStyle>;
|
|
33
|
+
/** Content rendered inside the content area */
|
|
34
|
+
children?: ReactNode;
|
|
35
|
+
}
|
|
36
|
+
export interface ItemRightProps {
|
|
37
|
+
/** Custom styles applied to the right part */
|
|
38
|
+
style?: StyleProp<ViewStyle>;
|
|
39
|
+
/** Content rendered inside right part */
|
|
40
|
+
children?: ReactNode;
|
|
41
|
+
}
|
|
42
|
+
declare const ObservedItem: any;
|
|
43
|
+
export default ObservedItem;
|
package/index.tsx
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { Children, type ReactNode } from 'react'
|
|
2
|
+
import { Image, type StyleProp, type ViewStyle } from 'react-native'
|
|
3
|
+
import { pug, observer } from 'startupjs'
|
|
4
|
+
import { themed } from '@startupjs-ui/core'
|
|
5
|
+
import Div, { type DivProps } from '@startupjs-ui/div'
|
|
6
|
+
import Icon, { type IconProps } from '@startupjs-ui/icon'
|
|
7
|
+
import Link from '@startupjs-ui/link'
|
|
8
|
+
import Span from '@startupjs-ui/span'
|
|
9
|
+
import './index.cssx.styl'
|
|
10
|
+
|
|
11
|
+
export const _PropsJsonSchema = {/* ItemProps */} // used in docs generation
|
|
12
|
+
|
|
13
|
+
export interface ItemProps extends Omit<DivProps, 'style' | 'onPress'> {
|
|
14
|
+
/** Custom styles applied to the root view */
|
|
15
|
+
style?: StyleProp<ViewStyle>
|
|
16
|
+
/** Content rendered inside Item */
|
|
17
|
+
children?: ReactNode
|
|
18
|
+
/** Navigation target passed to Link wrapper */
|
|
19
|
+
to?: string
|
|
20
|
+
/** Image URL displayed on the left side */
|
|
21
|
+
url?: string
|
|
22
|
+
/** Icon displayed on the left side when no image is provided */
|
|
23
|
+
icon?: IconProps['icon']
|
|
24
|
+
/** onPress handler */
|
|
25
|
+
onPress?: (event: any) => void
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function Item ({
|
|
29
|
+
style,
|
|
30
|
+
children,
|
|
31
|
+
to,
|
|
32
|
+
url,
|
|
33
|
+
icon,
|
|
34
|
+
onPress,
|
|
35
|
+
...props
|
|
36
|
+
}: ItemProps): ReactNode {
|
|
37
|
+
let Wrapper: any
|
|
38
|
+
const extraProps: Record<string, any> = {}
|
|
39
|
+
|
|
40
|
+
if (to) {
|
|
41
|
+
Wrapper = Link
|
|
42
|
+
extraProps.to = to
|
|
43
|
+
extraProps.block = true
|
|
44
|
+
} else {
|
|
45
|
+
Wrapper = Div
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let left: ReactNode = null
|
|
49
|
+
let content: ReactNode = null
|
|
50
|
+
let right: ReactNode = null
|
|
51
|
+
const contentChildren: ReactNode[] = []
|
|
52
|
+
|
|
53
|
+
Children.toArray(children).forEach((child: any) => {
|
|
54
|
+
if (!child || typeof child !== 'object') {
|
|
55
|
+
contentChildren.push(child)
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (ItemLeft === child.type) {
|
|
60
|
+
left = child
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (ItemRight === child.type) {
|
|
65
|
+
right = child
|
|
66
|
+
return
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (ItemContent === child.type) {
|
|
70
|
+
content = child
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
contentChildren.push(child)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
if (!left) {
|
|
78
|
+
if (icon) {
|
|
79
|
+
left = pug`
|
|
80
|
+
ItemLeft
|
|
81
|
+
Icon(icon=icon)
|
|
82
|
+
`
|
|
83
|
+
} else if (url) {
|
|
84
|
+
left = pug`
|
|
85
|
+
ItemLeft
|
|
86
|
+
Image.image(source={ uri: url })
|
|
87
|
+
`
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
content = content ??
|
|
92
|
+
(contentChildren.length === 1
|
|
93
|
+
? pug`
|
|
94
|
+
ItemContent= contentChildren[0]
|
|
95
|
+
`
|
|
96
|
+
: pug`
|
|
97
|
+
ItemContent= contentChildren
|
|
98
|
+
`
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
return pug`
|
|
102
|
+
Wrapper.root(
|
|
103
|
+
style=style
|
|
104
|
+
variant="highlight"
|
|
105
|
+
onPress=onPress
|
|
106
|
+
...extraProps
|
|
107
|
+
...props
|
|
108
|
+
)
|
|
109
|
+
= left
|
|
110
|
+
= content
|
|
111
|
+
= right
|
|
112
|
+
`
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface ItemLeftProps {
|
|
116
|
+
/** Custom styles applied to the left part */
|
|
117
|
+
style?: StyleProp<ViewStyle>
|
|
118
|
+
/** Content rendered inside left part */
|
|
119
|
+
children?: ReactNode
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function ItemLeft ({ style, children }: ItemLeftProps): ReactNode {
|
|
123
|
+
return pug`
|
|
124
|
+
Div.left(style=style)= children
|
|
125
|
+
`
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export interface ItemContentProps {
|
|
129
|
+
/** Custom styles applied to the content wrapper */
|
|
130
|
+
style?: StyleProp<ViewStyle>
|
|
131
|
+
/** Content rendered inside the content area */
|
|
132
|
+
children?: ReactNode
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function ItemContent ({ style, children }: ItemContentProps): ReactNode {
|
|
136
|
+
return pug`
|
|
137
|
+
if typeof children === 'string'
|
|
138
|
+
Span.content(style=style numberOfLines=1)= children
|
|
139
|
+
else
|
|
140
|
+
Div.content(style=style)= children
|
|
141
|
+
`
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface ItemRightProps {
|
|
145
|
+
/** Custom styles applied to the right part */
|
|
146
|
+
style?: StyleProp<ViewStyle>
|
|
147
|
+
/** Content rendered inside right part */
|
|
148
|
+
children?: ReactNode
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function ItemRight ({ style, children }: ItemRightProps): ReactNode {
|
|
152
|
+
return pug`
|
|
153
|
+
Div.right(style=style)= children
|
|
154
|
+
`
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const ObservedItem: any = observer(themed('Item', Item))
|
|
158
|
+
|
|
159
|
+
ObservedItem.Left = ItemLeft
|
|
160
|
+
ObservedItem.Content = ItemContent
|
|
161
|
+
ObservedItem.Right = ItemRight
|
|
162
|
+
|
|
163
|
+
export default ObservedItem
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@startupjs-ui/item",
|
|
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/link": "^0.1.3",
|
|
15
|
+
"@startupjs-ui/span": "^0.1.3"
|
|
16
|
+
},
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"react": "*",
|
|
19
|
+
"react-native": "*",
|
|
20
|
+
"startupjs": "*"
|
|
21
|
+
},
|
|
22
|
+
"gitHead": "fd964ebc3892d3dd0a6c85438c0af619cc50c3f0"
|
|
23
|
+
}
|