@startupjs-ui/div 0.3.0 → 0.3.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/CHANGELOG.md +11 -0
- package/index.tsx +35 -7
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.3.1](https://github.com/startupjs/startupjs-ui/compare/v0.3.0...v0.3.1) (2026-06-08)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* support inherited text styles from Div, support relative lineHeight ([#32](https://github.com/startupjs/startupjs-ui/issues/32)) ([47b56ab](https://github.com/startupjs/startupjs-ui/commit/47b56abca03b1d3ef1d977309deffd95a2de709d))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [0.3.0](https://github.com/startupjs/startupjs-ui/compare/v0.2.3...v0.3.0) (2026-05-27)
|
|
7
18
|
|
|
8
19
|
|
package/index.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useLayoutEffect, useState, useRef, type ReactNode, type RefObject } from 'react'
|
|
1
|
+
import { useContext, useLayoutEffect, useMemo, useState, useRef, type ReactNode, type RefObject } from 'react'
|
|
2
2
|
import {
|
|
3
3
|
View,
|
|
4
4
|
Pressable,
|
|
@@ -11,6 +11,12 @@ import {
|
|
|
11
11
|
import Animated from 'react-native-reanimated'
|
|
12
12
|
import { pug, observer, u, useDidUpdate } from 'startupjs'
|
|
13
13
|
import { colorToRGBA, getCssVariable, themed, type UIRole } from '@startupjs-ui/core'
|
|
14
|
+
import {
|
|
15
|
+
TextStyleContext,
|
|
16
|
+
getInheritedTextStyle,
|
|
17
|
+
mergeInheritedTextStyles,
|
|
18
|
+
omitInheritedTextStyle
|
|
19
|
+
} from '@startupjs-ui/span/textStyleContext'
|
|
14
20
|
import { useDecorateTooltipProps } from './useTooltip'
|
|
15
21
|
import STYLES from './index.cssx.styl'
|
|
16
22
|
|
|
@@ -98,7 +104,7 @@ export interface DivProps extends Omit<ViewProps, 'role'> {
|
|
|
98
104
|
}
|
|
99
105
|
|
|
100
106
|
function Div ({
|
|
101
|
-
style = [],
|
|
107
|
+
style: rawStyle = [],
|
|
102
108
|
children,
|
|
103
109
|
variant = 'opacity',
|
|
104
110
|
row,
|
|
@@ -125,9 +131,19 @@ function Div ({
|
|
|
125
131
|
...props
|
|
126
132
|
}: DivProps): ReactNode {
|
|
127
133
|
assertDeprecatedValues({ pushed, renderTooltip })
|
|
128
|
-
style = StyleSheet.flatten(
|
|
134
|
+
let style = StyleSheet.flatten(rawStyle) as ViewStyle | undefined
|
|
129
135
|
// on RN row-reverse switches margins and paddings sides, so we switch them back
|
|
130
136
|
if (isNative && reverse) style = reverseMarginPaddingSides(style)
|
|
137
|
+
|
|
138
|
+
const inheritedTextStyle = useContext(TextStyleContext)
|
|
139
|
+
const ownTextStyle = getInheritedTextStyle(style)
|
|
140
|
+
const nextInheritedTextStyleKey = simpleNumericHash(JSON.stringify([inheritedTextStyle, ownTextStyle]))
|
|
141
|
+
const nextInheritedTextStyle = useMemo(() => {
|
|
142
|
+
if (!ownTextStyle) return undefined
|
|
143
|
+
return mergeInheritedTextStyles(inheritedTextStyle, ownTextStyle)
|
|
144
|
+
}, [nextInheritedTextStyleKey]) // eslint-disable-line react-hooks/exhaustive-deps
|
|
145
|
+
omitInheritedTextStyle(style)
|
|
146
|
+
|
|
131
147
|
if (gap === true) gap = 2
|
|
132
148
|
const isPressable = hasPressHandler(props)
|
|
133
149
|
const fallbackRef = useRef<any>(null)
|
|
@@ -216,13 +232,19 @@ function Div ({
|
|
|
216
232
|
...renderProps
|
|
217
233
|
)= children
|
|
218
234
|
`
|
|
235
|
+
const styledDivElement = nextInheritedTextStyle
|
|
236
|
+
? pug`
|
|
237
|
+
TextStyleContext.Provider(value=nextInheritedTextStyle)
|
|
238
|
+
= divElement
|
|
239
|
+
`
|
|
240
|
+
: divElement
|
|
219
241
|
|
|
220
242
|
if (tooltipElement) {
|
|
221
243
|
return pug`
|
|
222
|
-
=
|
|
244
|
+
= styledDivElement
|
|
223
245
|
= tooltipElement
|
|
224
246
|
`
|
|
225
|
-
} else return
|
|
247
|
+
} else return styledDivElement
|
|
226
248
|
}
|
|
227
249
|
|
|
228
250
|
function isWebOnlyRole (role: unknown): role is Exclude<UIRole, ViewProps['role']> {
|
|
@@ -436,8 +458,8 @@ function hasPressHandler (props: Record<string, any>): boolean {
|
|
|
436
458
|
return PRESSABLE_PROPS.some(prop => props[prop])
|
|
437
459
|
}
|
|
438
460
|
|
|
439
|
-
function reverseMarginPaddingSides (style:
|
|
440
|
-
style
|
|
461
|
+
function reverseMarginPaddingSides (style: ViewStyle | undefined): ViewStyle | undefined {
|
|
462
|
+
if (!style) return style
|
|
441
463
|
const { paddingLeft, paddingRight, marginLeft, marginRight } = style
|
|
442
464
|
style.marginLeft = marginRight
|
|
443
465
|
style.marginRight = marginLeft
|
|
@@ -446,6 +468,12 @@ function reverseMarginPaddingSides (style: StyleProp<ViewStyle>) {
|
|
|
446
468
|
return style
|
|
447
469
|
}
|
|
448
470
|
|
|
471
|
+
function simpleNumericHash (s: string): number {
|
|
472
|
+
let h = 0
|
|
473
|
+
for (let i = 0; i < s.length; i++) h = Math.imul(31, h) + s.charCodeAt(i) | 0
|
|
474
|
+
return h
|
|
475
|
+
}
|
|
476
|
+
|
|
449
477
|
function assertDeprecatedValues ({ pushed, renderTooltip }: { pushed?: any, renderTooltip?: any }) {
|
|
450
478
|
if (DEPRECATED_PUSHED_VALUES.includes(pushed)) console.warn(ERRORS.DEPRECATED_PUSHED(pushed))
|
|
451
479
|
if (renderTooltip) console.warn(ERRORS.DEPRECATED_RENDER_TOOLTIP)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startupjs-ui/div",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@startupjs-ui/abstract-popover": "^0.3.0",
|
|
16
16
|
"@startupjs-ui/core": "^0.3.0",
|
|
17
|
-
"@startupjs-ui/span": "^0.3.
|
|
17
|
+
"@startupjs-ui/span": "^0.3.1"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"react": "*",
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"react-native-reanimated": ">=4.0.0",
|
|
23
23
|
"startupjs": "*"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "60311773bdc83f354c797a272774304502d28c58"
|
|
26
26
|
}
|