@molecule/app-ui-react-native 1.0.10 → 2.1.0
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/README.md +211 -331
- package/dist/components/Button.d.ts +2 -2
- package/dist/components/Button.d.ts.map +1 -1
- package/dist/components/Button.js +2 -2
- package/dist/components/Card.d.ts +3 -2
- package/dist/components/Card.d.ts.map +1 -1
- package/dist/components/Card.js +11 -3
- package/dist/components/Checkbox.d.ts +2 -2
- package/dist/components/Checkbox.d.ts.map +1 -1
- package/dist/components/Checkbox.js +4 -7
- package/dist/components/Input.d.ts +13 -2
- package/dist/components/Input.d.ts.map +1 -1
- package/dist/components/Input.js +5 -11
- package/dist/components/Layout.d.ts +3 -2
- package/dist/components/Layout.d.ts.map +1 -1
- package/dist/components/Layout.js +2 -2
- package/dist/components/Select.d.ts +2 -2
- package/dist/components/Select.d.ts.map +1 -1
- package/dist/components/Select.js +4 -6
- package/dist/components/Switch.d.ts +2 -2
- package/dist/components/Switch.d.ts.map +1 -1
- package/dist/components/Switch.js +3 -7
- package/dist/components/Textarea.d.ts +13 -2
- package/dist/components/Textarea.d.ts.map +1 -1
- package/dist/components/Textarea.js +2 -6
- package/dist/elements/Anchor.d.ts +15 -0
- package/dist/elements/Anchor.d.ts.map +1 -0
- package/dist/elements/Anchor.js +57 -0
- package/dist/elements/Box.d.ts +19 -0
- package/dist/elements/Box.d.ts.map +1 -0
- package/dist/elements/Box.js +150 -0
- package/dist/elements/CheckField.d.ts +18 -0
- package/dist/elements/CheckField.d.ts.map +1 -0
- package/dist/elements/CheckField.js +103 -0
- package/dist/elements/Disclosure.d.ts +11 -0
- package/dist/elements/Disclosure.d.ts.map +1 -0
- package/dist/elements/Disclosure.js +67 -0
- package/dist/elements/Fieldset.d.ts +16 -0
- package/dist/elements/Fieldset.d.ts.map +1 -0
- package/dist/elements/Fieldset.js +34 -0
- package/dist/elements/FileField.d.ts +12 -0
- package/dist/elements/FileField.d.ts.map +1 -0
- package/dist/elements/FileField.js +111 -0
- package/dist/elements/FormArea.d.ts +18 -0
- package/dist/elements/FormArea.d.ts.map +1 -0
- package/dist/elements/FormArea.js +42 -0
- package/dist/elements/GlyphIcon.d.ts +19 -0
- package/dist/elements/GlyphIcon.d.ts.map +1 -0
- package/dist/elements/GlyphIcon.js +43 -0
- package/dist/elements/Image.d.ts +17 -0
- package/dist/elements/Image.d.ts.map +1 -0
- package/dist/elements/Image.js +26 -0
- package/dist/elements/Link.d.ts +20 -0
- package/dist/elements/Link.d.ts.map +1 -0
- package/dist/elements/Link.js +53 -0
- package/dist/elements/Pressable.d.ts +18 -0
- package/dist/elements/Pressable.d.ts.map +1 -0
- package/dist/elements/Pressable.js +107 -0
- package/dist/elements/PulseDots.d.ts +15 -0
- package/dist/elements/PulseDots.d.ts.map +1 -0
- package/dist/elements/PulseDots.js +78 -0
- package/dist/elements/RangeField.d.ts +11 -0
- package/dist/elements/RangeField.d.ts.map +1 -0
- package/dist/elements/RangeField.js +259 -0
- package/dist/elements/RichText.d.ts +23 -0
- package/dist/elements/RichText.d.ts.map +1 -0
- package/dist/elements/RichText.js +55 -0
- package/dist/elements/Rule.d.ts +11 -0
- package/dist/elements/Rule.d.ts.map +1 -0
- package/dist/elements/Rule.js +19 -0
- package/dist/elements/ScrollArea.d.ts +21 -0
- package/dist/elements/ScrollArea.d.ts.map +1 -0
- package/dist/elements/ScrollArea.js +101 -0
- package/dist/elements/SelectAction.d.ts +20 -0
- package/dist/elements/SelectAction.d.ts.map +1 -0
- package/dist/elements/SelectAction.js +113 -0
- package/dist/elements/SelectField.d.ts +11 -0
- package/dist/elements/SelectField.d.ts.map +1 -0
- package/dist/elements/SelectField.js +220 -0
- package/dist/elements/SelectMenu.d.ts +19 -0
- package/dist/elements/SelectMenu.d.ts.map +1 -0
- package/dist/elements/SelectMenu.js +122 -0
- package/dist/elements/Svg.d.ts +155 -0
- package/dist/elements/Svg.d.ts.map +1 -0
- package/dist/elements/Svg.js +525 -0
- package/dist/elements/TableBox.d.ts +19 -0
- package/dist/elements/TableBox.d.ts.map +1 -0
- package/dist/elements/TableBox.js +87 -0
- package/dist/elements/TableCell.d.ts +16 -0
- package/dist/elements/TableCell.d.ts.map +1 -0
- package/dist/elements/TableCell.js +69 -0
- package/dist/elements/Text.d.ts +17 -0
- package/dist/elements/Text.d.ts.map +1 -0
- package/dist/elements/Text.js +96 -0
- package/dist/elements/TextField.d.ts +25 -0
- package/dist/elements/TextField.d.ts.map +1 -0
- package/dist/elements/TextField.js +257 -0
- package/dist/elements/accessibility.d.ts +36 -0
- package/dist/elements/accessibility.d.ts.map +1 -0
- package/dist/elements/accessibility.js +239 -0
- package/dist/elements/className.d.ts +45 -0
- package/dist/elements/className.d.ts.map +1 -0
- package/dist/elements/className.js +8 -0
- package/dist/elements/decimal.d.ts +5 -0
- package/dist/elements/decimal.d.ts.map +1 -0
- package/dist/elements/decimal.js +11 -0
- package/dist/elements/documentUrl.d.ts +35 -0
- package/dist/elements/documentUrl.d.ts.map +1 -0
- package/dist/elements/documentUrl.js +89 -0
- package/dist/elements/drag-drop.d.ts +11 -0
- package/dist/elements/drag-drop.d.ts.map +1 -0
- package/dist/elements/drag-drop.js +277 -0
- package/dist/elements/drag.d.ts +47 -0
- package/dist/elements/drag.d.ts.map +1 -0
- package/dist/elements/drag.js +362 -0
- package/dist/elements/events.d.ts +45 -0
- package/dist/elements/events.d.ts.map +1 -0
- package/dist/elements/events.js +101 -0
- package/dist/elements/fieldBounds.d.ts +5 -0
- package/dist/elements/fieldBounds.d.ts.map +1 -0
- package/dist/elements/fieldBounds.js +60 -0
- package/dist/elements/flow.d.ts +36 -0
- package/dist/elements/flow.d.ts.map +1 -0
- package/dist/elements/flow.js +47 -0
- package/dist/elements/form.d.ts +48 -0
- package/dist/elements/form.d.ts.map +1 -0
- package/dist/elements/form.js +112 -0
- package/dist/elements/grid.d.ts +96 -0
- package/dist/elements/grid.d.ts.map +1 -0
- package/dist/elements/grid.js +272 -0
- package/dist/elements/index.d.ts +36 -0
- package/dist/elements/index.d.ts.map +1 -0
- package/dist/elements/index.js +35 -0
- package/dist/elements/inherited.d.ts +181 -0
- package/dist/elements/inherited.d.ts.map +1 -0
- package/dist/elements/inherited.js +512 -0
- package/dist/elements/labels.d.ts +39 -0
- package/dist/elements/labels.d.ts.map +1 -0
- package/dist/elements/labels.js +163 -0
- package/dist/elements/measure.d.ts +27 -0
- package/dist/elements/measure.d.ts.map +1 -0
- package/dist/elements/measure.js +24 -0
- package/dist/elements/outsidePress.d.ts +31 -0
- package/dist/elements/outsidePress.d.ts.map +1 -0
- package/dist/elements/outsidePress.js +94 -0
- package/dist/elements/paste.d.ts +22 -0
- package/dist/elements/paste.d.ts.map +1 -0
- package/dist/elements/paste.js +49 -0
- package/dist/elements/press.d.ts +41 -0
- package/dist/elements/press.d.ts.map +1 -0
- package/dist/elements/press.js +131 -0
- package/dist/elements/rangeKeyboard.d.ts +41 -0
- package/dist/elements/rangeKeyboard.d.ts.map +1 -0
- package/dist/elements/rangeKeyboard.js +58 -0
- package/dist/elements/rangeValues.d.ts +20 -0
- package/dist/elements/rangeValues.d.ts.map +1 -0
- package/dist/elements/rangeValues.js +101 -0
- package/dist/elements/ref.d.ts +16 -0
- package/dist/elements/ref.d.ts.map +1 -0
- package/dist/elements/ref.js +22 -0
- package/dist/elements/reveal.d.ts +8 -0
- package/dist/elements/reveal.d.ts.map +1 -0
- package/dist/elements/reveal.js +10 -0
- package/dist/elements/scrollReveal.d.ts +19 -0
- package/dist/elements/scrollReveal.d.ts.map +1 -0
- package/dist/elements/scrollReveal.js +52 -0
- package/dist/elements/selectOptions.d.ts +25 -0
- package/dist/elements/selectOptions.d.ts.map +1 -0
- package/dist/elements/selectOptions.js +60 -0
- package/dist/elements/style.d.ts +30 -0
- package/dist/elements/style.d.ts.map +1 -0
- package/dist/elements/style.js +363 -0
- package/dist/elements/svgHover.d.ts +41 -0
- package/dist/elements/svgHover.d.ts.map +1 -0
- package/dist/elements/svgHover.js +152 -0
- package/dist/elements/table.d.ts +52 -0
- package/dist/elements/table.d.ts.map +1 -0
- package/dist/elements/table.js +104 -0
- package/dist/elements/types.d.ts +25 -0
- package/dist/elements/types.d.ts.map +1 -0
- package/dist/elements/types.js +8 -0
- package/dist/elements/viewport.d.ts +53 -0
- package/dist/elements/viewport.d.ts.map +1 -0
- package/dist/elements/viewport.js +62 -0
- package/dist/elements/wheelZoom.d.ts +11 -0
- package/dist/elements/wheelZoom.d.ts.map +1 -0
- package/dist/elements/wheelZoom.js +7 -0
- package/dist/index.d.ts +11 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -5
- package/dist/platform/focus.d.ts +31 -0
- package/dist/platform/focus.d.ts.map +1 -0
- package/dist/platform/focus.js +86 -0
- package/dist/platform/index.d.ts +31 -0
- package/dist/platform/index.d.ts.map +1 -0
- package/dist/platform/index.js +179 -0
- package/dist/platform/layout.d.ts +13 -0
- package/dist/platform/layout.d.ts.map +1 -0
- package/dist/platform/layout.js +15 -0
- package/dist/platform/position.d.ts +5 -0
- package/dist/platform/position.d.ts.map +1 -0
- package/dist/platform/position.js +177 -0
- package/dist/platform/stack.d.ts +86 -0
- package/dist/platform/stack.d.ts.map +1 -0
- package/dist/platform/stack.js +318 -0
- package/dist/types.d.ts +25 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +66 -8
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Text as NativeText } from 'react-native';
|
|
3
|
+
import { getFont } from '@molecule/app-fonts';
|
|
4
|
+
import { getClassMap } from '@molecule/app-ui';
|
|
5
|
+
import { nativeAccessibility } from './accessibility.js';
|
|
6
|
+
import { registerInline } from './flow.js';
|
|
7
|
+
import { useGridCell } from './grid.js';
|
|
8
|
+
import { dataAttributes, splitClasses, textElementClasses, useInheritedText, useTagClasses, } from './inherited.js';
|
|
9
|
+
import { useNativeRef } from './ref.js';
|
|
10
|
+
import { nativeStyle } from './style.js';
|
|
11
|
+
/** Glyph names already reported as missing from the icon font. */
|
|
12
|
+
const REPORTED = new Set();
|
|
13
|
+
/**
|
|
14
|
+
* A glyph of the icon font: a native `Text` drawing the glyph's codepoint in the icon font the app
|
|
15
|
+
* set (`setFont` with an `icon` font that has `glyphs`, such as
|
|
16
|
+
* `@molecule/app-fonts-material-symbols/native`), since a device draws neither ligatures nor
|
|
17
|
+
* variable axes. A name the font does not draw renders nothing.
|
|
18
|
+
*
|
|
19
|
+
* @param props - See {@link GlyphIconProps}.
|
|
20
|
+
* @returns The element, or `null`.
|
|
21
|
+
*/
|
|
22
|
+
export function GlyphIcon(props) {
|
|
23
|
+
const { name, filled, className, style, webStyle, ref } = props;
|
|
24
|
+
const cm = getClassMap();
|
|
25
|
+
const split = splitClasses(cm.cn(cm.iconGlyphFont, useTagClasses(className, 'span')), useInheritedText(), dataAttributes(props));
|
|
26
|
+
const nativeRef = useNativeRef(ref);
|
|
27
|
+
const gridStyle = useGridCell();
|
|
28
|
+
const font = getFont('icon');
|
|
29
|
+
const codepoint = font?.glyphs?.codepoint(name);
|
|
30
|
+
if (!font || codepoint === undefined) {
|
|
31
|
+
if (typeof __DEV__ !== 'undefined' && __DEV__ && !REPORTED.has(name)) {
|
|
32
|
+
REPORTED.add(name);
|
|
33
|
+
console.error(font?.glyphs
|
|
34
|
+
? `GlyphIcon: the icon font "${font.family}" has no glyph named "${name}".`
|
|
35
|
+
: `GlyphIcon "${name}": no icon font with glyphs is set. Call setFont() with one (nativeFont from @molecule/app-fonts-material-symbols/native) and load its nativeFiles with expo-font.`);
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
const family = filled ? (font.glyphs?.filledFamily ?? font.family) : font.family;
|
|
40
|
+
const own = nativeStyle(style, webStyle);
|
|
41
|
+
return (_jsx(NativeText, { ...nativeAccessibility(props, 'span'), ref: nativeRef, className: textElementClasses(split), style: [{ fontFamily: family }, own, gridStyle], children: String.fromCodePoint(codepoint) }));
|
|
42
|
+
}
|
|
43
|
+
registerInline(GlyphIcon, () => 'text');
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Image: a picture.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { ReactElement } from 'react';
|
|
7
|
+
import type { ImageProps } from '@molecule/app-ui';
|
|
8
|
+
import type { ElementRefProps } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* An image: a native `Image` with `alt` as its accessibility label; an empty `alt` hides a
|
|
11
|
+
* decorative image from assistive technology.
|
|
12
|
+
*
|
|
13
|
+
* @param props - See {@link ImageProps}.
|
|
14
|
+
* @returns The element.
|
|
15
|
+
*/
|
|
16
|
+
export declare function Image(props: ImageProps & ElementRefProps): ReactElement;
|
|
17
|
+
//# sourceMappingURL=Image.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Image.d.ts","sourceRoot":"","sources":["../../src/elements/Image.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAGzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAOlD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAKjD;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,eAAe,GAAG,YAAY,CAmBvE"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Image as NativeImage } from 'react-native';
|
|
3
|
+
import { nativeAccessibility } from './accessibility.js';
|
|
4
|
+
import { registerInline } from './flow.js';
|
|
5
|
+
import { useGridCell } from './grid.js';
|
|
6
|
+
import { replacedFlow } from './inherited.js';
|
|
7
|
+
import { useNativeRef } from './ref.js';
|
|
8
|
+
/** React Native's resize mode for a CSS `object-fit`. */
|
|
9
|
+
const RESIZE = { cover: 'cover', contain: 'contain', fill: 'stretch', none: 'center' };
|
|
10
|
+
/**
|
|
11
|
+
* An image: a native `Image` with `alt` as its accessibility label; an empty `alt` hides a
|
|
12
|
+
* decorative image from assistive technology.
|
|
13
|
+
*
|
|
14
|
+
* @param props - See {@link ImageProps}.
|
|
15
|
+
* @returns The element.
|
|
16
|
+
*/
|
|
17
|
+
export function Image(props) {
|
|
18
|
+
const { src, alt, width, height, className, style, onLoad, onError, ref } = props;
|
|
19
|
+
const { objectFit, ...box } = style ?? {};
|
|
20
|
+
return (_jsx(NativeImage, { ...nativeAccessibility({
|
|
21
|
+
...props,
|
|
22
|
+
'aria-label': alt || props['aria-label'],
|
|
23
|
+
'aria-hidden': alt === '' ? true : props['aria-hidden'],
|
|
24
|
+
}), ref: useNativeRef(ref), source: { uri: src }, className: className || undefined, style: [{ width, height }, box, useGridCell()], resizeMode: objectFit ? RESIZE[objectFit] : undefined, onLoad: onLoad ? () => onLoad() : undefined, onError: onError ? () => onError() : undefined }));
|
|
25
|
+
}
|
|
26
|
+
registerInline(Image, (props) => replacedFlow(props.className, 'img'));
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Link: an in-app or external link.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { ReactElement } from 'react';
|
|
7
|
+
import type { ElementLinkProps } from '@molecule/app-ui';
|
|
8
|
+
import type { ElementNode, ElementRefProps } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* A link: a native `Pressable` with the link role. A press runs `onClick`, then (unless the
|
|
11
|
+
* handler called `preventDefault()`) navigates through the router for an app path, or opens a URL
|
|
12
|
+
* outside the app. A link to the location already shown replaces it, as on the web. A URL outside
|
|
13
|
+
* the app needs no router: it opens through the device's URL handler in an app with none mounted,
|
|
14
|
+
* while an app path without one fails with the binding's no-router error, as on the web.
|
|
15
|
+
*
|
|
16
|
+
* @param props - See {@link ElementLinkProps}.
|
|
17
|
+
* @returns The element.
|
|
18
|
+
*/
|
|
19
|
+
export declare function Link(props: ElementLinkProps<ElementNode> & ElementRefProps): ReactElement;
|
|
20
|
+
//# sourceMappingURL=Link.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Link.d.ts","sourceRoot":"","sources":["../../src/elements/Link.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAKzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAmBxD,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE9D;;;;;;;;;GASG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,gBAAgB,CAAC,WAAW,CAAC,GAAG,eAAe,GAAG,YAAY,CAiEzF"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Linking, Pressable } from 'react-native';
|
|
3
|
+
import { useLinkRouter } from '@molecule/app-react';
|
|
4
|
+
import { formatLocation, parseLocation, resolveLinkPath } from '@molecule/app-routing';
|
|
5
|
+
import { nativeAccessibility } from './accessibility.js';
|
|
6
|
+
import { focusEvent, mouseEvent } from './events.js';
|
|
7
|
+
import { registerInline } from './flow.js';
|
|
8
|
+
import { useGridCell } from './grid.js';
|
|
9
|
+
import { blockInInline, dataAttributes, ElementScope, flowOf, isCssInline, layoutChildren, splitClasses, useInheritedText, useTagClasses, } from './inherited.js';
|
|
10
|
+
import { useNativeRef } from './ref.js';
|
|
11
|
+
import { nativeStyle } from './style.js';
|
|
12
|
+
/**
|
|
13
|
+
* A link: a native `Pressable` with the link role. A press runs `onClick`, then (unless the
|
|
14
|
+
* handler called `preventDefault()`) navigates through the router for an app path, or opens a URL
|
|
15
|
+
* outside the app. A link to the location already shown replaces it, as on the web. A URL outside
|
|
16
|
+
* the app needs no router: it opens through the device's URL handler in an app with none mounted,
|
|
17
|
+
* while an app path without one fails with the binding's no-router error, as on the web.
|
|
18
|
+
*
|
|
19
|
+
* @param props - See {@link ElementLinkProps}.
|
|
20
|
+
* @returns The element.
|
|
21
|
+
*/
|
|
22
|
+
export function Link(props) {
|
|
23
|
+
const { to, replace, state, title, className, style, webStyle, onClick, onMouseEnter, onMouseLeave, onFocus, onBlur, children, ref, } = props;
|
|
24
|
+
const router = useLinkRouter(to);
|
|
25
|
+
const split = splitClasses(useTagClasses(className, 'a'), useInheritedText(), dataAttributes(props));
|
|
26
|
+
const text = split.text;
|
|
27
|
+
const accessibility = nativeAccessibility({
|
|
28
|
+
...props,
|
|
29
|
+
role: props.role ?? 'link',
|
|
30
|
+
'aria-label': props['aria-label'] ?? title,
|
|
31
|
+
});
|
|
32
|
+
return (_jsx(ElementScope, { split: split, text: text, children: _jsx(Pressable, { ...accessibility, ref: useNativeRef(ref), className: split.view || undefined, style: [nativeStyle(style, webStyle), useGridCell()], onPress: (nativeEvent) => {
|
|
33
|
+
const event = mouseEvent(nativeEvent);
|
|
34
|
+
onClick?.(event);
|
|
35
|
+
if (event.defaultPrevented)
|
|
36
|
+
return;
|
|
37
|
+
const path = resolveLinkPath(to);
|
|
38
|
+
// `router` is null only for a URL outside the app with no router mounted, so that case
|
|
39
|
+
// opens the URL like every other one outside the app. An app path always has a router
|
|
40
|
+
// here: `useLinkRouter` threw the binding's no-router error without one.
|
|
41
|
+
if (router === null || path === null) {
|
|
42
|
+
void Linking.openURL(to);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const navigation = {
|
|
46
|
+
replace: replace ??
|
|
47
|
+
formatLocation(router.getLocation()) === formatLocation(parseLocation(path)),
|
|
48
|
+
...(state === undefined ? {} : { state }),
|
|
49
|
+
};
|
|
50
|
+
router.navigate(path, navigation);
|
|
51
|
+
}, onHoverIn: onMouseEnter ? () => onMouseEnter(mouseEvent(undefined)) : undefined, onHoverOut: onMouseLeave ? () => onMouseLeave(mouseEvent(undefined)) : undefined, onFocus: onFocus ? () => onFocus(focusEvent()) : undefined, onBlur: onBlur ? () => onBlur(focusEvent()) : undefined, children: layoutChildren(children, split) }) }));
|
|
52
|
+
}
|
|
53
|
+
registerInline(Link, (props) => blockInInline(flowOf(props.className, 'box', dataAttributes(props)), props.children, isCssInline(props.className, true, dataAttributes(props))));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pressable: an element the user activates.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { type ReactElement } from 'react';
|
|
7
|
+
import type { PressableProps } from '@molecule/app-ui';
|
|
8
|
+
import type { ElementNode, ElementRefProps } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Something the user activates: a native `Pressable`. `onClick` fires on press, the mouse
|
|
11
|
+
* handlers on hover where the device has a pointer, and a string child is drawn in a `Text` with
|
|
12
|
+
* the pressable's text classes. Key handlers are web-only.
|
|
13
|
+
*
|
|
14
|
+
* @param props - See {@link PressableProps}.
|
|
15
|
+
* @returns The element.
|
|
16
|
+
*/
|
|
17
|
+
export declare function Pressable(props: PressableProps<ElementNode> & ElementRefProps): ReactElement;
|
|
18
|
+
//# sourceMappingURL=Pressable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Pressable.d.ts","sourceRoot":"","sources":["../../src/elements/Pressable.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,YAAY,EAAmC,MAAM,OAAO,CAAA;AAG1E,OAAO,KAAK,EAAc,cAAc,EAAE,MAAM,kBAAkB,CAAA;AA0BlE,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE9D;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,CAAC,WAAW,CAAC,GAAG,eAAe,GAAG,YAAY,CA8G5F"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Pressable: an element the user activates.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { useCallback, useContext, useRef } from 'react';
|
|
8
|
+
import { Pressable as NativePressable, View } from 'react-native';
|
|
9
|
+
import { useOverlayTarget } from '../platform/focus.js';
|
|
10
|
+
import { nativeAccessibility } from './accessibility.js';
|
|
11
|
+
import { dragViewActions, useDragFrame, useNativeDrag } from './drag.js';
|
|
12
|
+
import { registerInline } from './flow.js';
|
|
13
|
+
import { DisabledScope, FormScope, useFormRegistration } from './form.js';
|
|
14
|
+
import { useGridCell } from './grid.js';
|
|
15
|
+
import { blockInInline, buttonText, dataAttributes, ElementScope, flowOf, isCssInline, layoutChildren, splitClasses, useInheritedText, useLineStart, useTagClasses, } from './inherited.js';
|
|
16
|
+
import { useLabelable, useReferencedLabelText } from './labels.js';
|
|
17
|
+
import { useOutsideTouch } from './outsidePress.js';
|
|
18
|
+
import { activatePress, AnchorPress, pressProps, useMousePress } from './press.js';
|
|
19
|
+
import { useNativeRef } from './ref.js';
|
|
20
|
+
import { nativeStyle } from './style.js';
|
|
21
|
+
/**
|
|
22
|
+
* Something the user activates: a native `Pressable`. `onClick` fires on press, the mouse
|
|
23
|
+
* handlers on hover where the device has a pointer, and a string child is drawn in a `Text` with
|
|
24
|
+
* the pressable's text classes. Key handlers are web-only.
|
|
25
|
+
*
|
|
26
|
+
* @param props - See {@link PressableProps}.
|
|
27
|
+
* @returns The element.
|
|
28
|
+
*/
|
|
29
|
+
export function Pressable(props) {
|
|
30
|
+
const { as, type, title, className, style, webStyle, children, ref } = props;
|
|
31
|
+
const form = useContext(FormScope);
|
|
32
|
+
const fieldsetDisabled = useContext(DisabledScope);
|
|
33
|
+
const anchorPress = useContext(AnchorPress);
|
|
34
|
+
const disabled = props.disabled || (as === 'button' && fieldsetDisabled);
|
|
35
|
+
const owner = as === 'button' && !props.form ? form : null;
|
|
36
|
+
const activate = type === 'reset' ? owner?.reset : type === 'button' ? undefined : owner?.submit;
|
|
37
|
+
const click = () => {
|
|
38
|
+
if (!disabled)
|
|
39
|
+
activatePress(props.onClick, activate);
|
|
40
|
+
};
|
|
41
|
+
useFormRegistration(owner?.buttons, { type, disabled, activate: click });
|
|
42
|
+
const label = useLabelable(props.id, as === 'button' ? click : undefined);
|
|
43
|
+
const description = useReferencedLabelText(props['aria-describedby']);
|
|
44
|
+
const inherited = useInheritedText();
|
|
45
|
+
const split = splitClasses(useTagClasses(className, as), as === 'button' ? buttonText(inherited) : inherited, dataAttributes(props));
|
|
46
|
+
const text = split.text;
|
|
47
|
+
const accessibility = nativeAccessibility({ ...props, 'aria-label': props['aria-label'] ?? label ?? title }, as);
|
|
48
|
+
const interaction = useMousePress(props, pressProps(props, activate, anchorPress), undefined, !disabled);
|
|
49
|
+
const host = useRef(null);
|
|
50
|
+
const forward = useNativeRef(ref);
|
|
51
|
+
const setHost = useCallback((view) => {
|
|
52
|
+
host.current = view;
|
|
53
|
+
forward?.(view);
|
|
54
|
+
}, [forward]);
|
|
55
|
+
const target = useOverlayTarget(setHost, disabled || accessibility['aria-disabled'] ? undefined : 'control');
|
|
56
|
+
const onTouchStart = useOutsideTouch(host);
|
|
57
|
+
const [frame, dragRef] = useDragFrame(target.ref);
|
|
58
|
+
const press = {
|
|
59
|
+
...interaction,
|
|
60
|
+
onFocus: (event) => {
|
|
61
|
+
if (!disabled)
|
|
62
|
+
target.remember();
|
|
63
|
+
interaction.onFocus?.(event);
|
|
64
|
+
},
|
|
65
|
+
onPress: disabled
|
|
66
|
+
? undefined
|
|
67
|
+
: (event) => {
|
|
68
|
+
target.remember();
|
|
69
|
+
interaction.onPress?.(event);
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
const secondary = disabled ? undefined : props.secondaryAction;
|
|
73
|
+
const responder = useNativeDrag(frame, {
|
|
74
|
+
drag: disabled ? undefined : props.drag,
|
|
75
|
+
secondary,
|
|
76
|
+
press,
|
|
77
|
+
});
|
|
78
|
+
const view = {
|
|
79
|
+
...accessibility,
|
|
80
|
+
onTouchStart: ref ? onTouchStart : undefined,
|
|
81
|
+
accessibilityHint: description ?? accessibility.accessibilityHint,
|
|
82
|
+
'aria-disabled': disabled || accessibility['aria-disabled'],
|
|
83
|
+
className: split.view || undefined,
|
|
84
|
+
style: [nativeStyle(style, webStyle), useLineStart(pressableFlow(props)), useGridCell()],
|
|
85
|
+
};
|
|
86
|
+
const content = layoutChildren(children, split);
|
|
87
|
+
return (_jsx(ElementScope, { split: split, text: text, children: responder ? (_jsx(View, { ...view, ref: dragRef, collapsable: false, accessible: true, ...responder, ...dragViewActions(props, press, press.onPress
|
|
88
|
+
? () => {
|
|
89
|
+
target.remember();
|
|
90
|
+
activatePress(props.onClick, activate, undefined, anchorPress);
|
|
91
|
+
}
|
|
92
|
+
: undefined, secondary), children: content })) : (_jsx(NativePressable, { ...view, ref: target.ref,
|
|
93
|
+
// A disabled button inside an anchor still consumes its tap without activating either.
|
|
94
|
+
disabled: disabled && anchorPress ? undefined : disabled, ...press, children: content })) }));
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* How a pressable flows: a button or a span is an inline box, a div or an li a block, unless its
|
|
98
|
+
* classes say otherwise.
|
|
99
|
+
*
|
|
100
|
+
* @param props - Its props.
|
|
101
|
+
* @returns Its inline kind.
|
|
102
|
+
*/
|
|
103
|
+
function pressableFlow(props) {
|
|
104
|
+
const data = dataAttributes(props);
|
|
105
|
+
return blockInInline(flowOf(props.className, props.as === 'button' || props.as === 'span' ? 'box' : null, data), props.children, isCssInline(props.className, props.as === 'span', data));
|
|
106
|
+
}
|
|
107
|
+
registerInline(Pressable, pressableFlow);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PulseDots: decorative typing activity paint on React Native.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { type ReactElement } from 'react';
|
|
7
|
+
import { type PulseDotsProps } from '@molecule/app-ui';
|
|
8
|
+
/**
|
|
9
|
+
* Draws three decorative dots with the ClassMap pulse and the OS reduced-motion preference.
|
|
10
|
+
*
|
|
11
|
+
* @param props - See {@link PulseDotsProps}.
|
|
12
|
+
* @returns Three animated views, with the caller providing their layout and status semantics.
|
|
13
|
+
*/
|
|
14
|
+
export declare function PulseDots({ size, durationMs }: PulseDotsProps): ReactElement;
|
|
15
|
+
//# sourceMappingURL=PulseDots.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PulseDots.d.ts","sourceRoot":"","sources":["../../src/elements/PulseDots.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,YAAY,EAAiD,MAAM,OAAO,CAAA;AAGxF,OAAO,EAAqC,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAOzF;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,cAAc,GAAG,YAAY,CAoF5E"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* PulseDots: decorative typing activity paint on React Native.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { useEffect, useLayoutEffect, useMemo, useState } from 'react';
|
|
8
|
+
import { AccessibilityInfo, Animated, Easing } from 'react-native';
|
|
9
|
+
import { DEFAULT_TYPING_PULSE, getClassMap } from '@molecule/app-ui';
|
|
10
|
+
import { registerInline } from './flow.js';
|
|
11
|
+
import { Circle, Svg } from './Svg.js';
|
|
12
|
+
const stationary = { opacity: 1, transform: [{ scale: 1 }] };
|
|
13
|
+
/**
|
|
14
|
+
* Draws three decorative dots with the ClassMap pulse and the OS reduced-motion preference.
|
|
15
|
+
*
|
|
16
|
+
* @param props - See {@link PulseDotsProps}.
|
|
17
|
+
* @returns Three animated views, with the caller providing their layout and status semantics.
|
|
18
|
+
*/
|
|
19
|
+
export function PulseDots({ size, durationMs }) {
|
|
20
|
+
const { peakAt, restAt, stagger, dimOpacity, dimScale } = getClassMap().typingPulse ?? DEFAULT_TYPING_PULSE;
|
|
21
|
+
const [motionAllowed, setMotionAllowed] = useState(false);
|
|
22
|
+
const [dots] = useState(() => [0, 1, 2].map(() => new Animated.Value(1)));
|
|
23
|
+
const animate = motionAllowed && durationMs > 0 && Number.isFinite(durationMs);
|
|
24
|
+
const paint = useMemo(() => dots.map((dot) => ({
|
|
25
|
+
opacity: dot.interpolate({ inputRange: [0, 1], outputRange: [dimOpacity, 1] }),
|
|
26
|
+
transform: [{ scale: dot.interpolate({ inputRange: [0, 1], outputRange: [dimScale, 1] }) }],
|
|
27
|
+
})), [dots, dimOpacity, dimScale]);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
let useInitialPreference = true;
|
|
30
|
+
const subscription = AccessibilityInfo.addEventListener('reduceMotionChanged', (reduced) => {
|
|
31
|
+
useInitialPreference = false;
|
|
32
|
+
setMotionAllowed(!reduced);
|
|
33
|
+
});
|
|
34
|
+
void AccessibilityInfo.isReduceMotionEnabled().then((reduced) => {
|
|
35
|
+
if (useInitialPreference)
|
|
36
|
+
setMotionAllowed(!reduced);
|
|
37
|
+
}, (_error) => {
|
|
38
|
+
// Keep the stationary dots when the OS cannot supply its preference.
|
|
39
|
+
});
|
|
40
|
+
return () => {
|
|
41
|
+
useInitialPreference = false;
|
|
42
|
+
subscription.remove();
|
|
43
|
+
};
|
|
44
|
+
}, []);
|
|
45
|
+
useLayoutEffect(() => {
|
|
46
|
+
if (!animate)
|
|
47
|
+
return;
|
|
48
|
+
const easeInOut = Easing.bezier(0.42, 0, 0.58, 1);
|
|
49
|
+
// Timing goes from one to zero, leaving the dot fully lit during its initial delay.
|
|
50
|
+
// The easing encodes the complete cycle so the native driver can repeat it on its own.
|
|
51
|
+
const easing = (fraction) => {
|
|
52
|
+
if (fraction < peakAt)
|
|
53
|
+
return 1 - easeInOut(fraction / peakAt);
|
|
54
|
+
if (fraction < restAt)
|
|
55
|
+
return easeInOut((fraction - peakAt) / (restAt - peakAt));
|
|
56
|
+
return 1;
|
|
57
|
+
};
|
|
58
|
+
const loops = dots.map((dot, index) => {
|
|
59
|
+
dot.setValue(1);
|
|
60
|
+
const loop = Animated.loop(Animated.timing(dot, {
|
|
61
|
+
toValue: 0,
|
|
62
|
+
duration: durationMs,
|
|
63
|
+
delay: index * durationMs * stagger,
|
|
64
|
+
easing,
|
|
65
|
+
isInteraction: false,
|
|
66
|
+
useNativeDriver: true,
|
|
67
|
+
}));
|
|
68
|
+
loop.start();
|
|
69
|
+
return loop;
|
|
70
|
+
});
|
|
71
|
+
return () => {
|
|
72
|
+
for (const loop of loops)
|
|
73
|
+
loop.stop();
|
|
74
|
+
};
|
|
75
|
+
}, [animate, dots, durationMs, peakAt, restAt, stagger]);
|
|
76
|
+
return (_jsx(_Fragment, { children: dots.map((_, index) => (_jsx(Animated.View, { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", pointerEvents: "none", style: [{ width: size, height: size }, animate ? paint[index] : stationary], children: _jsx(Svg, { width: size, height: size, "aria-hidden": true, children: _jsx(Circle, { cx: size / 2, cy: size / 2, r: size / 2, fill: "currentColor" }) }) }, index))) }));
|
|
77
|
+
}
|
|
78
|
+
registerInline(PulseDots, () => 'box');
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RangeField: a numeric platform slider with native forms and accessibility.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { ElementHandle, RangeFieldProps } from '@molecule/app-ui';
|
|
7
|
+
/**
|
|
8
|
+
* Renders the platform's slider and exposes its logical value to the native form and keyboard.
|
|
9
|
+
*/
|
|
10
|
+
export declare const RangeField: import("react").ForwardRefExoticComponent<RangeFieldProps & import("react").RefAttributes<ElementHandle>>;
|
|
11
|
+
//# sourceMappingURL=RangeField.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RangeField.d.ts","sourceRoot":"","sources":["../../src/elements/RangeField.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAyBH,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AA+CtE;;GAEG;AACH,eAAO,MAAM,UAAU,2GA8QtB,CAAA"}
|