@daisu-ui/ui 0.0.0-stage → 0.1.0-beta.4
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 +67 -0
- package/LICENSE +21 -0
- package/README.md +179 -2
- package/THIRD_PARTY_NOTICES.md +19 -0
- package/dist/ActionSheet.d.ts +45 -0
- package/dist/ActionSheet.jsx +37 -0
- package/dist/AnchoredBubble.d.ts +36 -0
- package/dist/AnchoredBubble.jsx +120 -0
- package/dist/Avatar.d.ts +35 -0
- package/dist/Avatar.jsx +29 -0
- package/dist/Backtop.d.ts +22 -0
- package/dist/Backtop.jsx +18 -0
- package/dist/Badge.d.ts +19 -0
- package/dist/Badge.jsx +11 -0
- package/dist/BarCode.d.ts +20 -0
- package/dist/BarCode.jsx +38 -0
- package/dist/Button.d.ts +21 -0
- package/dist/Button.jsx +19 -0
- package/dist/Calendar.d.ts +90 -0
- package/dist/Calendar.jsx +164 -0
- package/dist/CalendarView.d.ts +51 -0
- package/dist/CalendarView.jsx +136 -0
- package/dist/Card.d.ts +21 -0
- package/dist/Card.jsx +21 -0
- package/dist/Cascader.d.ts +75 -0
- package/dist/Cascader.jsx +212 -0
- package/dist/Cell.d.ts +34 -0
- package/dist/Cell.jsx +37 -0
- package/dist/Checkbox.d.ts +50 -0
- package/dist/Checkbox.jsx +74 -0
- package/dist/Circle.d.ts +19 -0
- package/dist/Circle.jsx +35 -0
- package/dist/Collapse.d.ts +31 -0
- package/dist/Collapse.jsx +61 -0
- package/dist/ConfigProvider.d.ts +15 -0
- package/dist/ConfigProvider.jsx +20 -0
- package/dist/CountDown.d.ts +20 -0
- package/dist/CountDown.jsx +15 -0
- package/dist/CountTo.d.ts +28 -0
- package/dist/CountTo.jsx +27 -0
- package/dist/Curtain.d.ts +29 -0
- package/dist/Curtain.jsx +51 -0
- package/dist/DatetimePicker.d.ts +46 -0
- package/dist/DatetimePicker.jsx +138 -0
- package/dist/DatetimePickerView.d.ts +38 -0
- package/dist/DatetimePickerView.jsx +36 -0
- package/dist/Dialog.d.ts +64 -0
- package/dist/Dialog.jsx +105 -0
- package/dist/Divider.d.ts +16 -0
- package/dist/Divider.jsx +9 -0
- package/dist/DropMenu.d.ts +55 -0
- package/dist/DropMenu.jsx +210 -0
- package/dist/Empty.d.ts +14 -0
- package/dist/Empty.jsx +14 -0
- package/dist/EmptyState.d.ts +6 -0
- package/dist/EmptyState.jsx +9 -0
- package/dist/Fab.d.ts +30 -0
- package/dist/Fab.jsx +127 -0
- package/dist/FloatingPanel.d.ts +21 -0
- package/dist/FloatingPanel.jsx +102 -0
- package/dist/Form.d.ts +63 -0
- package/dist/Form.jsx +108 -0
- package/dist/FormFieldRow.d.ts +56 -0
- package/dist/FormFieldRow.jsx +63 -0
- package/dist/Gap.d.ts +10 -0
- package/dist/Gap.jsx +14 -0
- package/dist/Grid.d.ts +47 -0
- package/dist/Grid.jsx +31 -0
- package/dist/Icon.d.ts +11 -0
- package/dist/Icon.jsx +12 -0
- package/dist/ImagePreview.d.ts +62 -0
- package/dist/ImagePreview.jsx +78 -0
- package/dist/Img.d.ts +28 -0
- package/dist/Img.jsx +59 -0
- package/dist/ImgCropper.d.ts +74 -0
- package/dist/ImgCropper.jsx +114 -0
- package/dist/IndexBar.d.ts +36 -0
- package/dist/IndexBar.jsx +149 -0
- package/dist/Input.d.ts +11 -0
- package/dist/Input.jsx +3 -0
- package/dist/InputNumber.d.ts +32 -0
- package/dist/InputNumber.jsx +165 -0
- package/dist/Keyboard.d.ts +37 -0
- package/dist/Keyboard.jsx +130 -0
- package/dist/Layout.d.ts +31 -0
- package/dist/Layout.jsx +14 -0
- package/dist/Loading.d.ts +18 -0
- package/dist/Loading.jsx +15 -0
- package/dist/Loadmore.d.ts +18 -0
- package/dist/Loadmore.jsx +16 -0
- package/dist/Navbar.d.ts +35 -0
- package/dist/Navbar.jsx +50 -0
- package/dist/NoticeBar.d.ts +30 -0
- package/dist/NoticeBar.jsx +86 -0
- package/dist/Notify.d.ts +34 -0
- package/dist/Notify.jsx +52 -0
- package/dist/NumberStepper.d.ts +11 -0
- package/dist/NumberStepper.jsx +41 -0
- package/dist/Overlay.d.ts +16 -0
- package/dist/Overlay.jsx +12 -0
- package/dist/PagedList.d.ts +13 -0
- package/dist/PagedList.jsx +36 -0
- package/dist/Pagination.d.ts +29 -0
- package/dist/Pagination.jsx +33 -0
- package/dist/PasswordInput.d.ts +16 -0
- package/dist/PasswordInput.jsx +20 -0
- package/dist/Picker.d.ts +61 -0
- package/dist/Picker.jsx +80 -0
- package/dist/PickerView.d.ts +43 -0
- package/dist/PickerView.jsx +142 -0
- package/dist/Popover.d.ts +23 -0
- package/dist/Popover.jsx +35 -0
- package/dist/Popup.d.ts +30 -0
- package/dist/Popup.jsx +32 -0
- package/dist/Progress.d.ts +17 -0
- package/dist/Progress.jsx +45 -0
- package/dist/QrCode.d.ts +46 -0
- package/dist/QrCode.jsx +67 -0
- package/dist/Radio.d.ts +21 -0
- package/dist/Radio.jsx +34 -0
- package/dist/Rate.d.ts +25 -0
- package/dist/Rate.jsx +39 -0
- package/dist/Resize.d.ts +17 -0
- package/dist/Resize.jsx +17 -0
- package/dist/RichText.d.ts +133 -0
- package/dist/RichText.jsx +288 -0
- package/dist/RootPortal.d.ts +11 -0
- package/dist/RootPortal.jsx +19 -0
- package/dist/Search.d.ts +39 -0
- package/dist/Search.jsx +94 -0
- package/dist/Segmented.d.ts +18 -0
- package/dist/Segmented.jsx +35 -0
- package/dist/SelectPicker.d.ts +54 -0
- package/dist/SelectPicker.jsx +136 -0
- package/dist/Sidebar.d.ts +34 -0
- package/dist/Sidebar.jsx +43 -0
- package/dist/Signature.d.ts +46 -0
- package/dist/Signature.jsx +203 -0
- package/dist/Skeleton.d.ts +27 -0
- package/dist/Skeleton.jsx +29 -0
- package/dist/SlideVerify.d.ts +27 -0
- package/dist/SlideVerify.jsx +138 -0
- package/dist/Slider.d.ts +21 -0
- package/dist/Slider.jsx +131 -0
- package/dist/SortButton.d.ts +16 -0
- package/dist/SortButton.jsx +19 -0
- package/dist/Steps.d.ts +23 -0
- package/dist/Steps.jsx +25 -0
- package/dist/Sticky.d.ts +17 -0
- package/dist/Sticky.jsx +69 -0
- package/dist/SwipeAction.d.ts +27 -0
- package/dist/SwipeAction.jsx +187 -0
- package/dist/Swiper.d.ts +54 -0
- package/dist/Swiper.jsx +94 -0
- package/dist/SwiperNav.d.ts +18 -0
- package/dist/SwiperNav.jsx +10 -0
- package/dist/Switch.d.ts +31 -0
- package/dist/Switch.jsx +46 -0
- package/dist/SyncedInput.d.ts +12 -0
- package/dist/SyncedInput.jsx +18 -0
- package/dist/SyncedTextarea.d.ts +11 -0
- package/dist/SyncedTextarea.jsx +18 -0
- package/dist/Tabbar.d.ts +37 -0
- package/dist/Tabbar.jsx +46 -0
- package/dist/Table.d.ts +51 -0
- package/dist/Table.jsx +125 -0
- package/dist/Tabs.d.ts +65 -0
- package/dist/Tabs.jsx +132 -0
- package/dist/Tag.d.ts +33 -0
- package/dist/Tag.jsx +63 -0
- package/dist/Text.d.ts +19 -0
- package/dist/Text.jsx +7 -0
- package/dist/TextField.d.ts +89 -0
- package/dist/TextField.jsx +149 -0
- package/dist/Textarea.d.ts +22 -0
- package/dist/Textarea.jsx +3 -0
- package/dist/Toast.d.ts +36 -0
- package/dist/Toast.jsx +30 -0
- package/dist/Tooltip.d.ts +8 -0
- package/dist/Tooltip.jsx +5 -0
- package/dist/Tour.d.ts +85 -0
- package/dist/Tour.jsx +150 -0
- package/dist/Transition.d.ts +32 -0
- package/dist/Transition.jsx +43 -0
- package/dist/Upload.d.ts +64 -0
- package/dist/Upload.jsx +163 -0
- package/dist/VideoPreview.d.ts +47 -0
- package/dist/VideoPreview.jsx +59 -0
- package/dist/Watermark.d.ts +36 -0
- package/dist/Watermark.jsx +18 -0
- package/dist/action-sheet.css +19 -0
- package/dist/avatar.css +23 -0
- package/dist/avatarModel.d.ts +8 -0
- package/dist/avatarModel.js +17 -0
- package/dist/backtop.css +6 -0
- package/dist/badge.css +15 -0
- package/dist/badgeModel.d.ts +2 -0
- package/dist/badgeModel.js +18 -0
- package/dist/bar-code.css +5 -0
- package/dist/barCodeModel.d.ts +80 -0
- package/dist/barCodeModel.js +99 -0
- package/dist/brand/logo.svg +8 -0
- package/dist/bubble.css +14 -0
- package/dist/bubblePosition.d.ts +19 -0
- package/dist/bubblePosition.js +41 -0
- package/dist/button.css +56 -0
- package/dist/calendar.css +56 -0
- package/dist/calendarModel.d.ts +62 -0
- package/dist/calendarModel.js +141 -0
- package/dist/card.css +8 -0
- package/dist/cascader.css +16 -0
- package/dist/cascaderModel.d.ts +21 -0
- package/dist/cascaderModel.js +32 -0
- package/dist/cell.css +41 -0
- package/dist/choice.css +27 -0
- package/dist/choice.d.ts +28 -0
- package/dist/choice.jsx +16 -0
- package/dist/circle.css +4 -0
- package/dist/circleModel.d.ts +15 -0
- package/dist/circleModel.js +31 -0
- package/dist/config-provider.css +2 -0
- package/dist/configContext.d.ts +23 -0
- package/dist/configContext.js +24 -0
- package/dist/configTheme.d.ts +3 -0
- package/dist/configTheme.js +22 -0
- package/dist/count-down.css +2 -0
- package/dist/count-to.css +8 -0
- package/dist/countDownModel.d.ts +11 -0
- package/dist/countDownModel.js +7 -0
- package/dist/countToModel.d.ts +3 -0
- package/dist/countToModel.js +3 -0
- package/dist/curtain.css +10 -0
- package/dist/datetime-picker.css +11 -0
- package/dist/datetimePickerModel.d.ts +47 -0
- package/dist/datetimePickerModel.js +128 -0
- package/dist/dialog.css +23 -0
- package/dist/divider.css +14 -0
- package/dist/drop-menu.css +28 -0
- package/dist/empty.css +7 -0
- package/dist/fab.css +23 -0
- package/dist/fabModel.d.ts +26 -0
- package/dist/fabModel.js +16 -0
- package/dist/floating-panel.css +6 -0
- package/dist/floatingPanelModel.d.ts +3 -0
- package/dist/floatingPanelModel.js +10 -0
- package/dist/form.css +10 -0
- package/dist/formContext.d.ts +7 -0
- package/dist/formContext.js +2 -0
- package/dist/formModel.d.ts +38 -0
- package/dist/formModel.js +16 -0
- package/dist/gap.css +1 -0
- package/dist/grid.css +17 -0
- package/dist/icon.css +8 -0
- package/dist/icons/LICENSE.tabler +21 -0
- package/dist/icons/paths.d.ts +309 -0
- package/dist/icons/paths.js +310 -0
- package/dist/icons/render.d.ts +2 -0
- package/dist/icons/render.js +5 -0
- package/dist/image-preview.css +8 -0
- package/dist/img-cropper.css +1 -0
- package/dist/img.css +5 -0
- package/dist/imgCropperModel.d.ts +55 -0
- package/dist/imgCropperModel.js +41 -0
- package/dist/imgModel.d.ts +13 -0
- package/dist/imgModel.js +22 -0
- package/dist/index-bar.css +12 -0
- package/dist/index.d.ts +200 -0
- package/dist/index.js +99 -0
- package/dist/indexBarModel.d.ts +19 -0
- package/dist/indexBarModel.js +37 -0
- package/dist/input-number.css +24 -0
- package/dist/inputNumberModel.d.ts +23 -0
- package/dist/inputNumberModel.js +40 -0
- package/dist/keyboard.css +26 -0
- package/dist/keyboardModel.d.ts +11 -0
- package/dist/keyboardModel.js +34 -0
- package/dist/layout.css +2 -0
- package/dist/legacy/RadioGroup.d.ts +13 -0
- package/dist/legacy/RadioGroup.jsx +13 -0
- package/dist/legacy-controls.css +87 -0
- package/dist/loading.css +31 -0
- package/dist/loadingModel.d.ts +2 -0
- package/dist/loadingModel.js +21 -0
- package/dist/loadmore.css +5 -0
- package/dist/navbar.css +16 -0
- package/dist/notice-bar.css +19 -0
- package/dist/notify.css +14 -0
- package/dist/overlay.css +2 -0
- package/dist/pagination.css +12 -0
- package/dist/paginationModel.d.ts +6 -0
- package/dist/paginationModel.js +7 -0
- package/dist/password-input.css +14 -0
- package/dist/passwordInputModel.d.ts +6 -0
- package/dist/passwordInputModel.js +11 -0
- package/dist/picker.css +42 -0
- package/dist/pickerModel.d.ts +32 -0
- package/dist/pickerModel.js +49 -0
- package/dist/popover.css +5 -0
- package/dist/popup.css +17 -0
- package/dist/progress.css +16 -0
- package/dist/progressModel.d.ts +12 -0
- package/dist/progressModel.js +19 -0
- package/dist/qr-code.css +4 -0
- package/dist/qrCodeModel.d.ts +36 -0
- package/dist/qrCodeModel.js +61 -0
- package/dist/rate.css +20 -0
- package/dist/rateModel.d.ts +4 -0
- package/dist/rateModel.js +38 -0
- package/dist/resize.css +2 -0
- package/dist/rich-text.css +19 -0
- package/dist/richTextMedia.d.ts +28 -0
- package/dist/richTextMedia.js +3 -0
- package/dist/richTextModel.d.ts +52 -0
- package/dist/richTextModel.js +195 -0
- package/dist/root-portal.css +1 -0
- package/dist/router/RouterView.d.ts +21 -0
- package/dist/router/RouterView.jsx +120 -0
- package/dist/router/core.d.ts +85 -0
- package/dist/router/core.js +255 -0
- package/dist/router/hooks.d.ts +17 -0
- package/dist/router/hooks.jsx +71 -0
- package/dist/router/index.d.ts +5 -0
- package/dist/router/index.js +3 -0
- package/dist/router/location.d.ts +8 -0
- package/dist/router/location.js +46 -0
- package/dist/router/router.css +7 -0
- package/dist/router/runtime.d.ts +1 -0
- package/dist/router/runtime.js +25 -0
- package/dist/search.css +23 -0
- package/dist/segmented.css +19 -0
- package/dist/segmentedModel.d.ts +10 -0
- package/dist/segmentedModel.js +8 -0
- package/dist/sidebar.css +18 -0
- package/dist/sidebarModel.d.ts +8 -0
- package/dist/sidebarModel.js +27 -0
- package/dist/signature.css +5 -0
- package/dist/signatureModel.d.ts +23 -0
- package/dist/signatureModel.js +80 -0
- package/dist/skeleton.css +16 -0
- package/dist/slide-verify.css +7 -0
- package/dist/slider.css +49 -0
- package/dist/sliderModel.d.ts +10 -0
- package/dist/sliderModel.js +27 -0
- package/dist/sort-button.css +12 -0
- package/dist/steps.css +35 -0
- package/dist/sticky.css +7 -0
- package/dist/styles.css +136 -0
- package/dist/styles.d.ts +1 -0
- package/dist/swipe-action.css +6 -0
- package/dist/swiper.css +27 -0
- package/dist/swiperAnimation.d.ts +3 -0
- package/dist/swiperAnimation.js +6 -0
- package/dist/swiperModel.d.ts +2 -0
- package/dist/swiperModel.js +3 -0
- package/dist/switch.css +12 -0
- package/dist/tabbar.css +17 -0
- package/dist/tabbarModel.d.ts +8 -0
- package/dist/tabbarModel.js +27 -0
- package/dist/table.css +21 -0
- package/dist/tableModel.d.ts +10 -0
- package/dist/tableModel.js +17 -0
- package/dist/tabs.css +31 -0
- package/dist/tabsModel.d.ts +7 -0
- package/dist/tabsModel.js +14 -0
- package/dist/tag.css +66 -0
- package/dist/text-field.css +15 -0
- package/dist/text.css +7 -0
- package/dist/textModel.d.ts +3 -0
- package/dist/textModel.js +24 -0
- package/dist/toast.css +13 -0
- package/dist/tokens.d.ts +34 -0
- package/dist/tokens.js +10 -0
- package/dist/tour.css +8 -0
- package/dist/transition.css +12 -0
- package/dist/upload.css +11 -0
- package/dist/useCountDown.d.ts +14 -0
- package/dist/useCountDown.js +73 -0
- package/dist/useDialog.d.ts +9 -0
- package/dist/useDialog.js +33 -0
- package/dist/useImagePreview.d.ts +7 -0
- package/dist/useImagePreview.js +17 -0
- package/dist/useNotify.d.ts +9 -0
- package/dist/useNotify.js +26 -0
- package/dist/usePressState.d.ts +6 -0
- package/dist/usePressState.js +17 -0
- package/dist/useToast.d.ts +11 -0
- package/dist/useToast.js +23 -0
- package/dist/useVideoPreview.d.ts +7 -0
- package/dist/useVideoPreview.js +17 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +4 -0
- package/dist/video-preview.css +7 -0
- package/dist/watermark.css +6 -0
- package/dist/web/imgCropperElement.d.ts +2 -0
- package/dist/web/imgCropperElement.js +309 -0
- package/dist/web/index.d.ts +6 -0
- package/dist/web/index.js +6 -0
- package/dist/web/qrCodeExportElement.d.ts +4 -0
- package/dist/web/qrCodeExportElement.js +70 -0
- package/dist/web/richTextMediaElement.d.ts +2 -0
- package/dist/web/richTextMediaElement.js +276 -0
- package/package.json +98 -4
package/dist/Badge.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
2
|
+
import type { CSSProperties } from '@lynx-js/types';
|
|
3
|
+
export type BadgeProps = {
|
|
4
|
+
value?: string | number;
|
|
5
|
+
max?: number;
|
|
6
|
+
top?: string | number;
|
|
7
|
+
right?: string | number;
|
|
8
|
+
isDot?: boolean;
|
|
9
|
+
hidden?: boolean;
|
|
10
|
+
type?: 'primary' | 'success' | 'warning' | 'danger' | 'info';
|
|
11
|
+
bgColor?: string;
|
|
12
|
+
showZero?: boolean;
|
|
13
|
+
shape?: 'circle' | 'square' | 'bubble';
|
|
14
|
+
border?: boolean;
|
|
15
|
+
children?: ReactNode;
|
|
16
|
+
className?: string;
|
|
17
|
+
style?: CSSProperties;
|
|
18
|
+
};
|
|
19
|
+
export declare function Badge({ value, max, top, right, isDot, hidden, type, bgColor, showZero, shape, border, children, className, style }: BadgeProps): import("@lynx-js/react").JSX.Element;
|
package/dist/Badge.jsx
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { badgeLabel, badgeOffset } from './badgeModel.js';
|
|
2
|
+
export function Badge({ value, max, top, right, isDot = false, hidden = false, type = 'danger', bgColor, showZero = false, shape = 'circle', border = false, children, className = '', style }) {
|
|
3
|
+
const label = badgeLabel(value, max, showZero);
|
|
4
|
+
const fixed = children !== undefined && children !== null && children !== false;
|
|
5
|
+
return <view className={`ui-badge ${className}`} style={style}>
|
|
6
|
+
{typeof children === 'string' || typeof children === 'number' ? <text>{children}</text> : children}
|
|
7
|
+
{!hidden && (isDot || label !== null) ? <view className={`ui-badge-content ui-badge-${type} ui-badge-${shape} ${fixed ? 'ui-badge-fixed' : ''} ${isDot ? 'ui-badge-dot' : ''} ${border ? 'ui-badge-bordered' : ''}`} style={{ top: badgeOffset(top), right: badgeOffset(right), backgroundColor: bgColor }}>
|
|
8
|
+
{isDot ? null : <text className="ui-badge-label">{label}</text>}
|
|
9
|
+
</view> : null}
|
|
10
|
+
</view>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { CSSProperties } from '@lynx-js/types';
|
|
2
|
+
import type { BarCodeOptions } from './barCodeModel.js';
|
|
3
|
+
export type { BarCodeFormat } from './barCodeModel.js';
|
|
4
|
+
export type BarCodeProps = BarCodeOptions & {
|
|
5
|
+
onValid?: (valid: boolean) => void;
|
|
6
|
+
onError?: (error: Error) => void;
|
|
7
|
+
className?: string;
|
|
8
|
+
style?: CSSProperties;
|
|
9
|
+
};
|
|
10
|
+
export type BarCodeRef = {
|
|
11
|
+
exportImage: () => Promise<string>;
|
|
12
|
+
getSvg: () => string;
|
|
13
|
+
};
|
|
14
|
+
/** Standard barcode encoders and native SVG; no DOM, Canvas, filesystem or host business API. */
|
|
15
|
+
export declare const BarCode: (props: BarCodeOptions & {
|
|
16
|
+
onValid?: (valid: boolean) => void;
|
|
17
|
+
onError?: (error: Error) => void;
|
|
18
|
+
className?: string;
|
|
19
|
+
style?: CSSProperties;
|
|
20
|
+
} & import("react").RefAttributes<BarCodeRef>) => React.ReactElement | null;
|
package/dist/BarCode.jsx
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { forwardRef, useEffect, useImperativeHandle, useMemo, useState } from '@lynx-js/react';
|
|
2
|
+
import { barCodeLayout, encodeBarCode } from './barCodeModel.js';
|
|
3
|
+
/** Standard barcode encoders and native SVG; no DOM, Canvas, filesystem or host business API. */
|
|
4
|
+
export const BarCode = forwardRef(function BarCode({ onValid, onError, className = '', style, ...props }, ref) {
|
|
5
|
+
const { value, format, width, height, text, font, fontSize, fontOptions, textMargin, background, lineColor, margin, marginTop, marginBottom, marginLeft, marginRight, displayValue, textAlign, textPosition } = props;
|
|
6
|
+
const encoded = useMemo(() => encodeBarCode(props), [value, format, width, height, text, font, fontSize, fontOptions, textMargin, background, lineColor, margin, marginTop, marginBottom, marginLeft, marginRight, displayValue, textAlign, textPosition]);
|
|
7
|
+
const [metrics, setMetrics] = useState({ key: '', widths: {} });
|
|
8
|
+
const o = encoded.options, metricKey = JSON.stringify([o.font, o.fontSize, o.fontOptions, o.value, o.text, o.format]);
|
|
9
|
+
const layout = useMemo(() => barCodeLayout(encoded, metrics.key === metricKey ? metrics.widths : {}), [encoded, metrics, metricKey]);
|
|
10
|
+
useEffect(() => { if (encoded.valid !== undefined)
|
|
11
|
+
onValid?.(encoded.valid); }, [encoded]);
|
|
12
|
+
useEffect(() => { if (layout.error)
|
|
13
|
+
onError?.(layout.error); }, [layout.error]);
|
|
14
|
+
useImperativeHandle(ref, () => ({
|
|
15
|
+
getSvg() {
|
|
16
|
+
'background only';
|
|
17
|
+
if (!layout.svg)
|
|
18
|
+
throw layout.error ?? new Error('Barcode value is empty');
|
|
19
|
+
return layout.svg;
|
|
20
|
+
},
|
|
21
|
+
async exportImage() {
|
|
22
|
+
'background only';
|
|
23
|
+
if (!layout.svg)
|
|
24
|
+
throw layout.error ?? new Error('Barcode value is empty');
|
|
25
|
+
return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(layout.svg)}`;
|
|
26
|
+
},
|
|
27
|
+
}), [layout]);
|
|
28
|
+
return <view className={`ui-bar-code ${className}`} style={{ width: `${encoded.empty ? 0 : Number.isFinite(o.width) && o.width > 0 ? o.width : 200}px`, height: `${encoded.empty ? 0 : Number.isFinite(o.height) && o.height > 0 ? o.height : 100}px`, ...style }} accessibility-element accessibility-label={String(value ?? '')}>
|
|
29
|
+
{layout.svg ? <svg className="ui-bar-code-svg" content={layout.barSvg} style={{ width: `${o.width}px`, height: `${o.height}px` }}/> : null}
|
|
30
|
+
{layout.texts.map((item, i) => <text key={`label:${i}`} className="ui-bar-code-label" style={{ left: `${item.x}px`, top: `${layout.textY - layout.fontSize}px`, width: `${item.width}px`, lineHeight: `${layout.fontSize * 1.25}px`, fontFamily: o.font, fontSize: `${layout.fontSize}px`, color: o.lineColor, textAlign: layout.segmented ? 'center' : o.textAlign, fontWeight: o.fontOptions.includes('bold') ? 'bold' : 'normal', fontStyle: o.fontOptions.includes('italic') ? 'italic' : 'normal' }}>{item.text}</text>)}
|
|
31
|
+
{layout.texts.map((item, i) => <text key={`${metricKey}:${i}:${item.text}`} className="ui-bar-code-measure" style={{ fontFamily: o.font, fontSize: `${o.fontSize}px`, fontWeight: o.fontOptions.includes('bold') ? 'bold' : 'normal', fontStyle: o.fontOptions.includes('italic') ? 'italic' : 'normal' }} bindlayoutchange={event => {
|
|
32
|
+
'background only';
|
|
33
|
+
const measured = event.detail.width;
|
|
34
|
+
if (Number.isFinite(measured) && measured > 0)
|
|
35
|
+
setMetrics(previous => previous.key === metricKey && previous.widths[item.text] === measured ? previous : { key: metricKey, widths: { ...previous.key === metricKey ? previous.widths : {}, [item.text]: measured } });
|
|
36
|
+
}}>{item.text}</text>)}
|
|
37
|
+
</view>;
|
|
38
|
+
});
|
package/dist/Button.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
2
|
+
export type ButtonTone = 'primary' | 'success' | 'info' | 'warning' | 'danger' | 'neutral';
|
|
3
|
+
export type ButtonVariant = 'solid' | 'plain' | 'dashed' | 'soft' | 'subtle' | 'text';
|
|
4
|
+
export type ButtonSize = 'mini' | 'small' | 'medium' | 'large';
|
|
5
|
+
export type ButtonProps = {
|
|
6
|
+
label?: string;
|
|
7
|
+
onTap?: () => void;
|
|
8
|
+
tone?: ButtonTone;
|
|
9
|
+
variant?: ButtonVariant;
|
|
10
|
+
size?: ButtonSize;
|
|
11
|
+
block?: boolean;
|
|
12
|
+
loading?: boolean;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
icon?: ReactNode;
|
|
15
|
+
round?: boolean;
|
|
16
|
+
hairline?: boolean;
|
|
17
|
+
className?: string;
|
|
18
|
+
accessibilityLabel?: string;
|
|
19
|
+
};
|
|
20
|
+
/** A Lynx-native command button using bindtap rather than browser click events. */
|
|
21
|
+
export declare function Button({ label, onTap, tone: toneProp, variant: variantProp, size: sizeProp, block, loading, disabled, icon, round: roundProp, hairline, className, accessibilityLabel }: ButtonProps): import("@lynx-js/react").JSX.Element;
|
package/dist/Button.jsx
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useConfigProvider } from './configContext.js';
|
|
2
|
+
import { usePressState } from './usePressState.js';
|
|
3
|
+
/** A Lynx-native command button using bindtap rather than browser click events. */
|
|
4
|
+
export function Button({ label, onTap, tone: toneProp, variant: variantProp, size: sizeProp, block = false, loading = false, disabled = false, icon, round: roundProp, hairline = false, className = '', accessibilityLabel }) {
|
|
5
|
+
const config = useConfigProvider().button;
|
|
6
|
+
const tone = toneProp ?? config.tone ?? config.type ?? 'primary', variant = variantProp ?? (config.variant === 'base' ? 'solid' : config.variant) ?? 'solid', size = sizeProp ?? config.size ?? 'medium', round = roundProp ?? config.round ?? false;
|
|
7
|
+
const inactive = disabled || loading;
|
|
8
|
+
const press = usePressState(!inactive);
|
|
9
|
+
const handleTap = () => {
|
|
10
|
+
'background only';
|
|
11
|
+
if (!inactive)
|
|
12
|
+
onTap?.();
|
|
13
|
+
};
|
|
14
|
+
return <view className={`ui-button ui-button-${tone} ui-button-${variant} ui-button-${size} ${block ? 'ui-button-block' : ''} ${disabled ? 'ui-button-disabled' : ''} ${inactive ? '' : 'ui-button-interactive'} ${press.pressed ? 'ui-button-pressed' : ''} ${round ? 'ui-button-round' : ''} ${hairline ? 'ui-button-hairline' : ''} ${!label && icon ? 'ui-button-icon-only' : ''} ${className}`} bindtap={handleTap} bindtouchstart={press.start} bindtouchend={press.end} bindtouchcancel={press.end} bindtouchmove={press.end} bindmousedown={press.start} global-bindmouseup={press.pressed ? press.end : undefined} accessibility-element accessibility-traits="button" accessibility-label={accessibilityLabel ?? label}>
|
|
15
|
+
<view className="ui-button-border"/>
|
|
16
|
+
{loading ? <view className="ui-button-spinner"><view className="ui-button-spinner-ring"/></view> : icon ? <view className="ui-button-icon">{typeof icon === 'string' ? <text>{icon}</text> : icon}</view> : null}
|
|
17
|
+
{label ? <text className="ui-button-label">{label}</text> : null}
|
|
18
|
+
</view>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
2
|
+
import type { CalendarViewProps } from "./CalendarView.jsx";
|
|
3
|
+
import type { CalendarType, CalendarValue } from './calendarModel.js';
|
|
4
|
+
export { CalendarView } from "./CalendarView.jsx";
|
|
5
|
+
export type { CalendarViewProps, CalendarViewRef } from "./CalendarView.jsx";
|
|
6
|
+
export type { CalendarType, CalendarValue, CalendarDayItem, CalendarDayType, CalendarSwitchMode } from './calendarModel.js';
|
|
7
|
+
export type CalendarRef = {
|
|
8
|
+
open: () => void;
|
|
9
|
+
close: () => void;
|
|
10
|
+
};
|
|
11
|
+
export type CalendarShortcut = {
|
|
12
|
+
text: string;
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
};
|
|
15
|
+
export type CalendarProps = Omit<CalendarViewProps, 'onChange'> & {
|
|
16
|
+
visible?: boolean;
|
|
17
|
+
onVisibleChange?: (visible: boolean) => void;
|
|
18
|
+
title?: string;
|
|
19
|
+
confirmText?: string;
|
|
20
|
+
showConfirm?: boolean;
|
|
21
|
+
onConfirm?: (event: {
|
|
22
|
+
value: CalendarValue;
|
|
23
|
+
type: CalendarType;
|
|
24
|
+
}) => void;
|
|
25
|
+
onChange?: (event: {
|
|
26
|
+
value: CalendarValue;
|
|
27
|
+
}) => void;
|
|
28
|
+
onPickChange?: (event: {
|
|
29
|
+
value: CalendarValue;
|
|
30
|
+
}) => void;
|
|
31
|
+
onCancel?: () => void;
|
|
32
|
+
onOpen?: () => void;
|
|
33
|
+
onClose?: () => void;
|
|
34
|
+
beforeConfirm?: (value: CalendarValue) => boolean | Promise<boolean>;
|
|
35
|
+
innerDisplayFormat?: (value: number | null, endpoint: 'start' | 'end', type: CalendarType) => string;
|
|
36
|
+
ellipsis?: boolean;
|
|
37
|
+
showTypeSwitch?: boolean;
|
|
38
|
+
shortcuts?: readonly CalendarShortcut[];
|
|
39
|
+
onShortcutsClick?: (event: {
|
|
40
|
+
item: CalendarShortcut;
|
|
41
|
+
index: number;
|
|
42
|
+
}) => CalendarValue | Promise<CalendarValue>;
|
|
43
|
+
confirmLeft?: ReactNode;
|
|
44
|
+
confirmRight?: ReactNode;
|
|
45
|
+
viewClassName?: string;
|
|
46
|
+
closeOnClickModal?: boolean;
|
|
47
|
+
duration?: number;
|
|
48
|
+
rootPortal?: boolean;
|
|
49
|
+
safeAreaInsetBottom?: boolean;
|
|
50
|
+
safeAreaBottom?: number;
|
|
51
|
+
zIndex?: number;
|
|
52
|
+
};
|
|
53
|
+
export declare const Calendar: (props: Omit<CalendarViewProps, "onChange"> & {
|
|
54
|
+
visible?: boolean;
|
|
55
|
+
onVisibleChange?: (visible: boolean) => void;
|
|
56
|
+
title?: string;
|
|
57
|
+
confirmText?: string;
|
|
58
|
+
showConfirm?: boolean;
|
|
59
|
+
onConfirm?: (event: {
|
|
60
|
+
value: CalendarValue;
|
|
61
|
+
type: CalendarType;
|
|
62
|
+
}) => void;
|
|
63
|
+
onChange?: (event: {
|
|
64
|
+
value: CalendarValue;
|
|
65
|
+
}) => void;
|
|
66
|
+
onPickChange?: (event: {
|
|
67
|
+
value: CalendarValue;
|
|
68
|
+
}) => void;
|
|
69
|
+
onCancel?: () => void;
|
|
70
|
+
onOpen?: () => void;
|
|
71
|
+
onClose?: () => void;
|
|
72
|
+
beforeConfirm?: (value: CalendarValue) => boolean | Promise<boolean>;
|
|
73
|
+
innerDisplayFormat?: (value: number | null, endpoint: "start" | "end", type: CalendarType) => string;
|
|
74
|
+
ellipsis?: boolean;
|
|
75
|
+
showTypeSwitch?: boolean;
|
|
76
|
+
shortcuts?: readonly CalendarShortcut[];
|
|
77
|
+
onShortcutsClick?: (event: {
|
|
78
|
+
item: CalendarShortcut;
|
|
79
|
+
index: number;
|
|
80
|
+
}) => CalendarValue | Promise<CalendarValue>;
|
|
81
|
+
confirmLeft?: ReactNode;
|
|
82
|
+
confirmRight?: ReactNode;
|
|
83
|
+
viewClassName?: string;
|
|
84
|
+
closeOnClickModal?: boolean;
|
|
85
|
+
duration?: number;
|
|
86
|
+
rootPortal?: boolean;
|
|
87
|
+
safeAreaInsetBottom?: boolean;
|
|
88
|
+
safeAreaBottom?: number;
|
|
89
|
+
zIndex?: number;
|
|
90
|
+
} & import("react").RefAttributes<CalendarRef>) => React.ReactElement | null;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { forwardRef, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState } from '@lynx-js/react';
|
|
2
|
+
import { ActionSheet } from "./ActionSheet.jsx";
|
|
3
|
+
import { Button } from "./Button.jsx";
|
|
4
|
+
import { Icon } from "./Icon.jsx";
|
|
5
|
+
import { Tabs } from "./Tabs.jsx";
|
|
6
|
+
import { Tag } from "./Tag.jsx";
|
|
7
|
+
import { FormFieldContext } from './formContext.js';
|
|
8
|
+
import { CalendarView } from "./CalendarView.jsx";
|
|
9
|
+
import { calendarComplete, calendarNormalize, calendarRange, calendarWeekNumber } from './calendarModel.js';
|
|
10
|
+
export { CalendarView } from "./CalendarView.jsx";
|
|
11
|
+
const pad = (value) => String(value).padStart(2, '0');
|
|
12
|
+
function innerLabel(value, endpoint, type) {
|
|
13
|
+
if (value === null)
|
|
14
|
+
return `${endpoint === 'start' ? '开始' : '结束'}${type === 'weekrange' ? '周' : type === 'monthrange' ? '月份' : '时间'}`;
|
|
15
|
+
const date = new Date(value), day = `${pad(date.getFullYear() % 100)}年${pad(date.getMonth() + 1)}月${pad(date.getDate())}日`;
|
|
16
|
+
return type === 'weekrange' ? `${date.getFullYear()} 第${pad(calendarWeekNumber(value))}周` : type === 'monthrange' ? `${date.getFullYear()}年${pad(date.getMonth() + 1)}月` : type === 'datetimerange' ? `${day} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}` : day;
|
|
17
|
+
}
|
|
18
|
+
export const Calendar = forwardRef(function Calendar({ visible, onVisibleChange, title = '选择日期', confirmText = '确定', showConfirm = true, onConfirm, onChange, onPickChange, onCancel, onOpen, onClose, beforeConfirm, innerDisplayFormat = innerLabel, ellipsis = false, showTypeSwitch = false, shortcuts = [], onShortcutsClick, confirmLeft, confirmRight, viewClassName = '', closeOnClickModal = true, duration = 200, rootPortal = false, safeAreaInsetBottom = true, safeAreaBottom = 0, zIndex = 100, value, type = 'date', disabled: disabledProp, className = '', style, ...props }, ref) {
|
|
19
|
+
const field = useContext(FormFieldContext), disabled = disabledProp ?? field?.disabled ?? false;
|
|
20
|
+
const [innerVisible, setInnerVisible] = useState(false), [innerValue, setInnerValue] = useState(null), show = visible ?? innerVisible, sourceValue = value === undefined ? innerValue : value;
|
|
21
|
+
const { minDate, maxDate, firstDayOfWeek, maxRange, allowSameDay, defaultTime, formatter, timeFilter, hideSecond, switchMode } = props;
|
|
22
|
+
const model = useMemo(() => ({ type, minDate, maxDate, firstDayOfWeek, maxRange, allowSameDay, defaultTime }), [type, minDate, maxDate, firstDayOfWeek, maxRange, allowSameDay, defaultTime]);
|
|
23
|
+
const source = useMemo(() => ({ sourceValue, model, show, disabled, formatter, timeFilter, hideSecond, switchMode, showTypeSwitch }), [sourceValue, model, show, disabled, formatter, timeFilter, hideSecond, switchMode, showTypeSwitch]);
|
|
24
|
+
const latest = useRef(source);
|
|
25
|
+
latest.current = source;
|
|
26
|
+
const [ready, setReady] = useState(), [draft, setDraft] = useState(null), [activeType, setActiveType] = useState(type), [busy, setBusy] = useState(false), [shortcut, setShortcut] = useState(-1);
|
|
27
|
+
const needsReveal = useRef(false);
|
|
28
|
+
const selection = useRef(draft), selectedType = useRef(activeType), view = useRef(null), generation = useRef(0), pending = useRef(false), opened = useRef(show), committed = useRef({ prop: type, type }), openCallback = useRef(onOpen);
|
|
29
|
+
openCallback.current = onOpen;
|
|
30
|
+
useEffect(() => { if (needsReveal.current) {
|
|
31
|
+
needsReveal.current = false;
|
|
32
|
+
view.current?.scrollIntoView();
|
|
33
|
+
} }, [draft]);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
generation.current++;
|
|
36
|
+
pending.current = false;
|
|
37
|
+
setBusy(false);
|
|
38
|
+
opened.current = show;
|
|
39
|
+
if (committed.current.prop !== type)
|
|
40
|
+
committed.current = { prop: type, type };
|
|
41
|
+
if (show) {
|
|
42
|
+
const nextType = showTypeSwitch ? committed.current.type : type, next = calendarNormalize(sourceValue, { ...model, type: nextType });
|
|
43
|
+
selection.current = next;
|
|
44
|
+
selectedType.current = nextType;
|
|
45
|
+
setActiveType(nextType);
|
|
46
|
+
setDraft(next);
|
|
47
|
+
setShortcut(-1);
|
|
48
|
+
setReady(source);
|
|
49
|
+
}
|
|
50
|
+
}, [source]);
|
|
51
|
+
useEffect(() => { if (show)
|
|
52
|
+
openCallback.current?.(); }, [show]);
|
|
53
|
+
useEffect(() => () => { generation.current++; opened.current = false; }, []);
|
|
54
|
+
const changeVisible = (next) => {
|
|
55
|
+
'background only';
|
|
56
|
+
if (visible === undefined)
|
|
57
|
+
setInnerVisible(next);
|
|
58
|
+
onVisibleChange?.(next);
|
|
59
|
+
};
|
|
60
|
+
const close = (cancelled = false) => {
|
|
61
|
+
'background only';
|
|
62
|
+
if (!opened.current)
|
|
63
|
+
return;
|
|
64
|
+
opened.current = false;
|
|
65
|
+
generation.current++;
|
|
66
|
+
pending.current = false;
|
|
67
|
+
setBusy(false);
|
|
68
|
+
if (cancelled)
|
|
69
|
+
onCancel?.();
|
|
70
|
+
changeVisible(false);
|
|
71
|
+
onClose?.();
|
|
72
|
+
};
|
|
73
|
+
useImperativeHandle(ref, () => ({ open: () => {
|
|
74
|
+
'background only';
|
|
75
|
+
if (!show && !disabled)
|
|
76
|
+
changeVisible(true);
|
|
77
|
+
}, close: () => close(true) }), [show, disabled, visible, onVisibleChange, onCancel, onClose]);
|
|
78
|
+
const confirm = async (suppliedValue) => {
|
|
79
|
+
'background only';
|
|
80
|
+
if (!opened.current || disabled || pending.current)
|
|
81
|
+
return;
|
|
82
|
+
const next = suppliedValue === undefined ? view.current?.getSelected() ?? selection.current : suppliedValue;
|
|
83
|
+
if (!calendarComplete(next, selectedType.current))
|
|
84
|
+
return;
|
|
85
|
+
selection.current = next;
|
|
86
|
+
setDraft(next);
|
|
87
|
+
pending.current = true;
|
|
88
|
+
setBusy(true);
|
|
89
|
+
const ticket = ++generation.current, snapshot = latest.current;
|
|
90
|
+
try {
|
|
91
|
+
if (!await (beforeConfirm?.(next) ?? true) || ticket !== generation.current || snapshot !== latest.current || !opened.current)
|
|
92
|
+
return;
|
|
93
|
+
committed.current = { prop: type, type: selectedType.current };
|
|
94
|
+
if (value === undefined)
|
|
95
|
+
setInnerValue(next);
|
|
96
|
+
onChange?.({ value: next });
|
|
97
|
+
onConfirm?.({ value: next, type: selectedType.current });
|
|
98
|
+
close();
|
|
99
|
+
}
|
|
100
|
+
catch { /* Rejected confirmation keeps the draft available. */ }
|
|
101
|
+
finally {
|
|
102
|
+
if (ticket === generation.current) {
|
|
103
|
+
pending.current = false;
|
|
104
|
+
setBusy(false);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const update = (next, shortcutIndex = -1) => {
|
|
109
|
+
'background only';
|
|
110
|
+
if (!opened.current || disabled || pending.current)
|
|
111
|
+
return;
|
|
112
|
+
selection.current = next;
|
|
113
|
+
setDraft(next);
|
|
114
|
+
setShortcut(shortcutIndex);
|
|
115
|
+
onPickChange?.({ value: next });
|
|
116
|
+
if (!showConfirm && calendarComplete(next, selectedType.current))
|
|
117
|
+
void confirm(next);
|
|
118
|
+
};
|
|
119
|
+
const chooseShortcut = async (item, index) => {
|
|
120
|
+
'background only';
|
|
121
|
+
if (!onShortcutsClick || !opened.current || disabled || pending.current)
|
|
122
|
+
return;
|
|
123
|
+
const ticket = ++generation.current, snapshot = latest.current;
|
|
124
|
+
pending.current = true;
|
|
125
|
+
setBusy(true);
|
|
126
|
+
try {
|
|
127
|
+
const next = await onShortcutsClick({ item, index });
|
|
128
|
+
if (ticket !== generation.current || snapshot !== latest.current || !opened.current)
|
|
129
|
+
return;
|
|
130
|
+
pending.current = false;
|
|
131
|
+
setBusy(false);
|
|
132
|
+
needsReveal.current = true;
|
|
133
|
+
update(calendarNormalize(next, { ...model, type: selectedType.current }), index);
|
|
134
|
+
}
|
|
135
|
+
catch { /* Failed shortcuts leave the existing draft intact. */ }
|
|
136
|
+
finally {
|
|
137
|
+
if (ticket === generation.current) {
|
|
138
|
+
pending.current = false;
|
|
139
|
+
setBusy(false);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
const endpoints = Array.isArray(draft) ? draft : [], range = calendarRange(activeType), types = calendarRange(type) ? ['daterange', 'weekrange', 'monthrange'] : ['date', 'week', 'month'];
|
|
144
|
+
return <ActionSheet show={show} onClose={() => close(true)} title={title} titleClassName="ui-calendar-header" className={`ui-calendar ${className}`} style={style} duration={duration} closeOnClickModal={closeOnClickModal} rootPortal={rootPortal} safeAreaInsetBottom={safeAreaInsetBottom} safeAreaBottom={safeAreaBottom} zIndex={zIndex} renderClose={() => <><Icon name="close" size={24} color="#4e5369" className="ui-calendar-close-light"/><Icon name="close" size={24} color="#e5e6eb" className="ui-calendar-close-dark"/></>}>
|
|
145
|
+
{showTypeSwitch ? <Tabs className="ui-calendar-tabs" items={types.map((name, index) => ({ name, title: ['日', '周', '月'][index] }))} value={activeType} onChange={next => {
|
|
146
|
+
'background only';
|
|
147
|
+
if (!opened.current || disabled || busy)
|
|
148
|
+
return;
|
|
149
|
+
selectedType.current = next;
|
|
150
|
+
setActiveType(next);
|
|
151
|
+
setShortcut(-1);
|
|
152
|
+
}}/> : null}
|
|
153
|
+
{shortcuts.length ? <view className="ui-calendar-shortcuts">{shortcuts.map((item, index) => <Tag key={index} type={shortcut === index ? 'primary' : 'default'} variant={shortcut === index ? 'dark' : 'light'} label={item.text} onTap={() => {
|
|
154
|
+
'background only';
|
|
155
|
+
void chooseShortcut(item, index);
|
|
156
|
+
}}/>)}</view> : null}
|
|
157
|
+
{range ? <view className="ui-calendar-range">{['start', 'end'].map((endpoint, index) => <view key={endpoint} className={`ui-calendar-range-item ${endpoints[index] == null ? 'ui-calendar-range-placeholder' : ''}`}><text className={ellipsis ? 'ui-calendar-range-ellipsis' : ''}>{innerDisplayFormat(endpoints[index] ?? null, endpoint, activeType)}</text><view className="ui-calendar-range-line"/></view>).flatMap((item, index) => index ? [<view key="separator" className="ui-calendar-range-separator"/>, item] : [item])}</view> : null}
|
|
158
|
+
{ready && (!show || ready === source) ? <CalendarView {...props} ref={view} value={draft} type={activeType} disabled={disabled || busy || !show} className={viewClassName} onChange={({ value }) => update(value)}/> : null}
|
|
159
|
+
{showConfirm ? <view className="ui-calendar-confirm"><view className="ui-calendar-confirm-line"/>{confirmLeft}<view className="ui-calendar-confirm-button"><Button size="large" round={false} label={confirmText} disabled={disabled || !calendarComplete(draft, activeType)} loading={busy} onTap={() => {
|
|
160
|
+
'background only';
|
|
161
|
+
void confirm();
|
|
162
|
+
}}/></view>{confirmRight}</view> : null}
|
|
163
|
+
</ActionSheet>;
|
|
164
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { CSSProperties } from '@lynx-js/types';
|
|
2
|
+
import type { DatetimeFilter } from './datetimePickerModel.js';
|
|
3
|
+
import type { CalendarDayItem, CalendarModelProps, CalendarSwitchMode, CalendarValue } from './calendarModel.js';
|
|
4
|
+
export type CalendarViewProps = CalendarModelProps & {
|
|
5
|
+
value?: CalendarValue;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
panelHeight?: number;
|
|
8
|
+
showPanelTitle?: boolean;
|
|
9
|
+
switchMode?: CalendarSwitchMode;
|
|
10
|
+
rangePrompt?: string;
|
|
11
|
+
formatter?: (day: CalendarDayItem) => Partial<CalendarDayItem>;
|
|
12
|
+
onChange?: (event: {
|
|
13
|
+
value: CalendarValue;
|
|
14
|
+
}) => void;
|
|
15
|
+
onOverRange?: () => void;
|
|
16
|
+
timeFilter?: DatetimeFilter;
|
|
17
|
+
timeItemHeight?: number;
|
|
18
|
+
timeVisibleItemCount?: number;
|
|
19
|
+
hideSecond?: boolean;
|
|
20
|
+
immediateChange?: boolean;
|
|
21
|
+
onPickStart?: () => void;
|
|
22
|
+
onPickEnd?: () => void;
|
|
23
|
+
className?: string;
|
|
24
|
+
style?: CSSProperties;
|
|
25
|
+
};
|
|
26
|
+
export type CalendarViewRef = {
|
|
27
|
+
scrollIntoView: () => void;
|
|
28
|
+
getSelected: () => CalendarValue;
|
|
29
|
+
};
|
|
30
|
+
export declare const CalendarView: (props: CalendarModelProps & {
|
|
31
|
+
value?: CalendarValue;
|
|
32
|
+
disabled?: boolean;
|
|
33
|
+
panelHeight?: number;
|
|
34
|
+
showPanelTitle?: boolean;
|
|
35
|
+
switchMode?: CalendarSwitchMode;
|
|
36
|
+
rangePrompt?: string;
|
|
37
|
+
formatter?: (day: CalendarDayItem) => Partial<CalendarDayItem>;
|
|
38
|
+
onChange?: (event: {
|
|
39
|
+
value: CalendarValue;
|
|
40
|
+
}) => void;
|
|
41
|
+
onOverRange?: () => void;
|
|
42
|
+
timeFilter?: DatetimeFilter;
|
|
43
|
+
timeItemHeight?: number;
|
|
44
|
+
timeVisibleItemCount?: number;
|
|
45
|
+
hideSecond?: boolean;
|
|
46
|
+
immediateChange?: boolean;
|
|
47
|
+
onPickStart?: () => void;
|
|
48
|
+
onPickEnd?: () => void;
|
|
49
|
+
className?: string;
|
|
50
|
+
style?: CSSProperties;
|
|
51
|
+
} & import("react").RefAttributes<CalendarViewRef>) => React.ReactElement | null;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { forwardRef, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState } from '@lynx-js/react';
|
|
2
|
+
import { Icon } from "./Icon.jsx";
|
|
3
|
+
import { DatetimePickerView } from "./DatetimePickerView.jsx";
|
|
4
|
+
import { FormFieldContext } from './formContext.js';
|
|
5
|
+
import { Toast } from "./Toast.jsx";
|
|
6
|
+
import { useToast } from './useToast.js';
|
|
7
|
+
import { calendarAddDays, calendarBounds, calendarComplete, calendarMidnight, calendarMonth, calendarPanels, calendarPick, calendarRange, calendarScrollTarget, calendarState, calendarTime, calendarValues } from './calendarModel.js';
|
|
8
|
+
const unitLabel = (type, value) => `${String(value).padStart(2, '0')}${type === 'hour' ? '时' : type === 'minute' ? '分' : '秒'}`;
|
|
9
|
+
const panelLabel = (date, monthly) => { const d = new Date(date); return `${d.getFullYear()}年${monthly ? '' : `${d.getMonth() + 1}月`}`; };
|
|
10
|
+
export const CalendarView = forwardRef(function CalendarView({ value, type = 'date', minDate, maxDate, firstDayOfWeek = 0, maxRange, allowSameDay = false, defaultTime, disabled: disabledProp, panelHeight = 316, showPanelTitle = true, switchMode = 'none', formatter, rangePrompt, onChange, onOverRange, timeFilter, timeItemHeight = 44, timeVisibleItemCount = 3, hideSecond = false, immediateChange = false, onPickStart, onPickEnd, className = '', style }, ref) {
|
|
11
|
+
const field = useContext(FormFieldContext), disabled = disabledProp ?? field?.disabled ?? false;
|
|
12
|
+
const [inner, setInner] = useState(null), current = value === undefined ? inner : value, currentRef = useRef(current);
|
|
13
|
+
currentRef.current = current;
|
|
14
|
+
const first = ((Math.trunc(firstDayOfWeek) % 7) + 7) % 7, model = useMemo(() => ({ type, minDate, maxDate, firstDayOfWeek: first, maxRange, allowSameDay, defaultTime }), [type, minDate, maxDate, first, maxRange, allowSameDay, defaultTime]);
|
|
15
|
+
const bounds = useMemo(() => calendarBounds(model), [minDate, maxDate]), monthly = calendarMonth(type), switching = switchMode !== 'none';
|
|
16
|
+
const [display, setDisplay] = useState(() => Math.max(bounds.min, Math.min(bounds.max, calendarValues(current)[0] ?? Date.now()))), [offset, setOffset] = useState(0), [timeIndex, setTimeIndex] = useState(type === 'datetimerange' && calendarComplete(current ?? null, type) ? 1 : 0);
|
|
17
|
+
const scroll = useRef(null), time = useRef(null), toast = useToast();
|
|
18
|
+
const panels = useMemo(() => calendarPanels({ type, minDate, maxDate, firstDayOfWeek: first }, switching, display), [type, minDate, maxDate, first, switching, display]);
|
|
19
|
+
const reveal = () => {
|
|
20
|
+
'background only';
|
|
21
|
+
const anchor = Math.max(bounds.min, Math.min(bounds.max, calendarValues(currentRef.current)[0] ?? Date.now()));
|
|
22
|
+
if (switching) {
|
|
23
|
+
setDisplay(anchor);
|
|
24
|
+
setOffset(0);
|
|
25
|
+
scroll.current?.invoke({ method: 'scrollTo', params: { offset: 0, smooth: false } }).exec();
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
const target = calendarScrollTarget(panels, currentRef.current ?? null, model);
|
|
29
|
+
setOffset(target.offset);
|
|
30
|
+
scroll.current?.invoke({ method: 'scrollTo', params: { offset: target.offset, smooth: false } }).exec();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
useEffect(reveal, [type, minDate, maxDate, first, switching]);
|
|
34
|
+
useEffect(() => { setTimeIndex(type === 'datetimerange' && calendarComplete(currentRef.current ?? null, type) ? 1 : 0); }, [type]);
|
|
35
|
+
const emit = (next) => {
|
|
36
|
+
'background only';
|
|
37
|
+
if (disabled)
|
|
38
|
+
return;
|
|
39
|
+
if (value === undefined) {
|
|
40
|
+
currentRef.current = next;
|
|
41
|
+
setInner(next);
|
|
42
|
+
}
|
|
43
|
+
onChange?.({ value: next });
|
|
44
|
+
};
|
|
45
|
+
const choose = (date) => {
|
|
46
|
+
'background only';
|
|
47
|
+
if (disabled)
|
|
48
|
+
return;
|
|
49
|
+
const result = calendarPick(model, currentRef.current ?? null, date);
|
|
50
|
+
if (!result)
|
|
51
|
+
return;
|
|
52
|
+
if (result.overRange) {
|
|
53
|
+
onOverRange?.();
|
|
54
|
+
toast.show(rangePrompt ?? `选择范围不能超过${maxRange}${monthly ? '个月' : type === 'weekrange' ? '周' : '天'}`);
|
|
55
|
+
}
|
|
56
|
+
setTimeIndex(result.timeIndex ?? 0);
|
|
57
|
+
emit(result.value);
|
|
58
|
+
};
|
|
59
|
+
const times = calendarValues(current), activeTime = times[timeIndex] ?? times[0], showTime = calendarTime(type) && activeTime !== undefined;
|
|
60
|
+
const timeString = (date) => { const d = new Date(date); return [d.getHours(), d.getMinutes(), ...(hideSecond ? [] : [d.getSeconds()])].map(value => String(value).padStart(2, '0')).join(':'); };
|
|
61
|
+
const combineTime = (next) => {
|
|
62
|
+
const date = new Date(activeTime), [h = 0, m = 0, s = 0] = next.split(':').map(Number);
|
|
63
|
+
date.setHours(h, m, s, 0);
|
|
64
|
+
let stamp = Math.max(bounds.min, Math.min(bounds.max, date.getTime()));
|
|
65
|
+
if (type === 'datetimerange') {
|
|
66
|
+
if (timeIndex === 0 && times[1] !== undefined)
|
|
67
|
+
stamp = Math.min(stamp, times[1]);
|
|
68
|
+
if (timeIndex === 1 && times[0] !== undefined)
|
|
69
|
+
stamp = Math.max(stamp, times[0]);
|
|
70
|
+
const next = Array.isArray(currentRef.current) ? [...currentRef.current] : [];
|
|
71
|
+
next[timeIndex] = stamp;
|
|
72
|
+
return next;
|
|
73
|
+
}
|
|
74
|
+
return stamp;
|
|
75
|
+
};
|
|
76
|
+
useImperativeHandle(ref, () => ({ scrollIntoView: reveal, getSelected: () => {
|
|
77
|
+
'background only';
|
|
78
|
+
const selected = time.current?.getSelected().value;
|
|
79
|
+
return showTime && typeof selected === 'string' && selected ? combineTime(selected) : currentRef.current ?? null;
|
|
80
|
+
} }), [panels, model, current, showTime, timeIndex, activeTime, hideSecond, disabled, switching]);
|
|
81
|
+
const sameDay = (stamp) => stamp !== undefined && calendarMidnight(stamp) === calendarMidnight(activeTime);
|
|
82
|
+
const timeMin = Math.max(sameDay(bounds.min) ? bounds.min : -Infinity, type === 'datetimerange' && timeIndex === 1 && sameDay(times[0]) ? times[0] : -Infinity);
|
|
83
|
+
const timeMax = Math.min(sameDay(bounds.max) ? bounds.max : Infinity, type === 'datetimerange' && timeIndex === 0 && sameDay(times[1]) ? times[1] : Infinity);
|
|
84
|
+
const height = Math.max(0, Number.isFinite(panelHeight) ? panelHeight : 316), scrollHeight = Math.max(0, height - (showTime ? 120 : 0)) + (monthly ? showPanelTitle ? 26 : 16 : 0);
|
|
85
|
+
const activePanel = Math.max(0, panels.findIndex(panel => panel.offset + panel.height > offset)), titleDate = switching ? panels[0].date : panels[activePanel]?.date ?? display;
|
|
86
|
+
const visible = switching ? panels : panels.filter(panel => panel.offset + panel.height >= offset - 320 && panel.offset <= offset + scrollHeight + 320), total = panels.reduce((sum, panel) => sum + panel.height, 0), firstOffset = visible[0]?.offset ?? 0, lastOffset = visible.length ? visible[visible.length - 1].offset + visible[visible.length - 1].height : 0;
|
|
87
|
+
const moveTarget = (amount, years = false) => { const d = new Date(display); d.setDate(1); if (monthly || years)
|
|
88
|
+
d.setFullYear(d.getFullYear() + amount);
|
|
89
|
+
else
|
|
90
|
+
d.setMonth(d.getMonth() + amount); return d.getTime(); };
|
|
91
|
+
const canMove = (amount, years = false) => { const d = new Date(moveTarget(amount, years)), min = new Date(bounds.min), max = new Date(bounds.max), key = monthly ? d.getFullYear() : d.getFullYear() * 12 + d.getMonth(), low = monthly ? min.getFullYear() : min.getFullYear() * 12 + min.getMonth(), high = monthly ? max.getFullYear() : max.getFullYear() * 12 + max.getMonth(); return key >= low && key <= high; };
|
|
92
|
+
const control = (amount, years = false) => <view className={`ui-calendar-control ${canMove(amount, years) ? '' : 'ui-calendar-control-disabled'}`} bindtap={() => {
|
|
93
|
+
'background only';
|
|
94
|
+
if (!disabled && canMove(amount, years)) {
|
|
95
|
+
setDisplay(moveTarget(amount, years));
|
|
96
|
+
setOffset(0);
|
|
97
|
+
scroll.current?.invoke({ method: 'scrollTo', params: { offset: 0, smooth: false } }).exec();
|
|
98
|
+
}
|
|
99
|
+
}} accessibility-element accessibility-traits="button" accessibility-label={`${amount < 0 ? '上一' : '下一'}${years || monthly ? '年' : '月'}`}><Icon name={years ? amount < 0 ? 'double-left' : 'double-right' : amount < 0 ? 'left' : 'right'} size={20}/></view>;
|
|
100
|
+
return <view className={`ui-calendar-view ${monthly ? 'ui-calendar-view-months' : ''} ${className}`} style={style}>
|
|
101
|
+
{switching ? <view className="ui-calendar-controls"><view className="ui-calendar-control-side">{!monthly && switchMode === 'year-month' ? control(-1, true) : null}{control(-1)}</view><text>{panelLabel(titleDate, monthly)}</text><view className="ui-calendar-control-side">{control(1)}{!monthly && switchMode === 'year-month' ? control(1, true) : null}</view></view> : null}
|
|
102
|
+
{!monthly ? <view className="ui-calendar-weekdays">{Array.from({ length: 7 }, (_, i) => <text key={i}>{['日', '一', '二', '三', '四', '五', '六'][(i + first) % 7]}</text>)}</view> : null}
|
|
103
|
+
{!switching && showPanelTitle ? <text className="ui-calendar-panel-title">{panelLabel(titleDate, monthly)}</text> : null}
|
|
104
|
+
<scroll-view ref={scroll} className="ui-calendar-scroll" scroll-orientation="vertical" scroll-bar-enable={false} enable-nested-scroll force-can-scroll style={{ height: `${scrollHeight}px` }} bindscroll={event => {
|
|
105
|
+
'background only';
|
|
106
|
+
if (!switching)
|
|
107
|
+
setOffset(Math.max(0, event.detail.scrollTop));
|
|
108
|
+
}}>
|
|
109
|
+
{firstOffset ? <view style={{ height: `${firstOffset}px` }}/> : null}
|
|
110
|
+
{visible.map(panel => {
|
|
111
|
+
const d = new Date(panel.date), year = d.getFullYear(), month = d.getMonth(), count = monthly ? 12 : new Date(year, month + 1, 0).getDate(), empty = monthly ? 0 : (d.getDay() - first + 7) % 7;
|
|
112
|
+
return <view className="ui-calendar-month" key={panel.date}>{panel.title ? <text className="ui-calendar-panel-title">{panelLabel(panel.date, monthly)}</text> : null}<view className="ui-calendar-days">
|
|
113
|
+
{empty ? <view style={{ width: `${empty * 100 / 7}%`, height: '60px', marginBottom: '4px' }}/> : null}
|
|
114
|
+
{Array.from({ length: count }, (_, i) => {
|
|
115
|
+
const date = new Date(year, monthly ? i : month, monthly ? 1 : i + 1).getTime(), rawType = calendarState(date, current ?? null, model), lastRow = monthly ? i >= 8 : Math.floor((empty + i) / 7) === panel.rows - 1;
|
|
116
|
+
const base = { date, text: monthly ? `${i + 1}月` : String(i + 1), type: rawType, disabled: monthly ? new Date(year, i + 1, 0).getTime() < bounds.minDay || date > bounds.maxDay : date < bounds.minDay || date > bounds.maxDay };
|
|
117
|
+
const item = { ...base, ...formatter?.({ ...base }) }, inactive = disabled || base.disabled || item.disabled, state = item.type, incomplete = calendarRange(type) && calendarValues(current).length < 2 && !type.startsWith('week');
|
|
118
|
+
return <view key={date} className={`ui-calendar-day ${monthly ? 'ui-calendar-day-month' : ''} ui-calendar-day-${state} ${inactive ? 'ui-calendar-day-disabled' : ''} ${incomplete ? 'ui-calendar-day-without-end' : ''} ${type === 'dates' ? 'ui-calendar-day-multiple' : ''} ${item.customClass ?? ''}`} style={{ marginBottom: lastRow ? '0px' : '4px' }} bindtap={() => {
|
|
119
|
+
'background only';
|
|
120
|
+
if (!inactive)
|
|
121
|
+
choose(date);
|
|
122
|
+
}} accessibility-element accessibility-traits="button" accessibility-label={`${year}年${monthly ? i + 1 : month + 1}月${monthly ? '' : `${i + 1}日`}${inactive ? ',禁用' : ''}`}>
|
|
123
|
+
{(state === 'start' || state === 'end') && !incomplete ? <view className={`ui-calendar-range-half ui-calendar-range-half-${state}`}/> : null}<view className="ui-calendar-day-inner">{item.topInfo ? <text className="ui-calendar-day-top">{item.topInfo}</text> : null}<text className="ui-calendar-day-label">{item.text}</text>{item.bottomInfo ? <text className="ui-calendar-day-bottom">{item.bottomInfo}</text> : null}</view>
|
|
124
|
+
</view>;
|
|
125
|
+
})}</view></view>;
|
|
126
|
+
})}
|
|
127
|
+
{total > lastOffset ? <view style={{ height: `${total - lastOffset}px` }}/> : null}
|
|
128
|
+
</scroll-view>
|
|
129
|
+
{showTime ? <view className="ui-calendar-time">{type === 'datetimerange' ? <view className="ui-calendar-time-label"><text>{timeIndex === 0 ? '开始' : '结束'}</text></view> : null}<view className="ui-calendar-time-picker"><DatetimePickerView key={`${timeIndex}:${calendarMidnight(activeTime)}`} ref={time} type="time" value={timeString(activeTime)} useSecond={!hideSecond} itemHeight={timeItemHeight} visibleItemCount={timeVisibleItemCount} filter={timeFilter} formatter={unitLabel} disabled={disabled} immediateChange={immediateChange} onPickStart={onPickStart} onPickEnd={onPickEnd} boundaryMinDate={Number.isFinite(timeMin) ? timeMin : undefined} boundaryMaxDate={Number.isFinite(timeMax) ? timeMax : undefined} onChange={({ value }) => {
|
|
130
|
+
'background only';
|
|
131
|
+
if (typeof value === 'string' && value)
|
|
132
|
+
emit(combineTime(value));
|
|
133
|
+
}}/></view></view> : null}
|
|
134
|
+
<Toast {...toast.props}/>
|
|
135
|
+
</view>;
|
|
136
|
+
});
|
package/dist/Card.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ReactNode } from '@lynx-js/react';
|
|
2
|
+
import type { CSSProperties } from '@lynx-js/types';
|
|
3
|
+
export type CardProps = {
|
|
4
|
+
title?: ReactNode;
|
|
5
|
+
description?: string;
|
|
6
|
+
children?: ReactNode;
|
|
7
|
+
footer?: ReactNode;
|
|
8
|
+
variant?: 'business' | 'standard';
|
|
9
|
+
type?: 'rectangle';
|
|
10
|
+
customTitleClass?: string;
|
|
11
|
+
customContentClass?: string;
|
|
12
|
+
customFooterClass?: string;
|
|
13
|
+
className?: string;
|
|
14
|
+
style?: CSSProperties;
|
|
15
|
+
};
|
|
16
|
+
export declare function Card({ title, description, children, footer, variant, type, customTitleClass, customContentClass, customFooterClass, className, style }: CardProps): import("@lynx-js/react").JSX.Element;
|
|
17
|
+
export declare function SectionTitle({ eyebrow, title, description }: {
|
|
18
|
+
eyebrow?: string;
|
|
19
|
+
title: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
}): import("@lynx-js/react").JSX.Element;
|
package/dist/Card.jsx
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
function content(value) { return typeof value === 'string' || typeof value === 'number' ? <text className="ui-card-copy">{value}</text> : value; }
|
|
2
|
+
export function Card({ title, description, children, footer, variant, type, customTitleClass = '', customContentClass = '', customFooterClass = '', className = '', style }) {
|
|
3
|
+
const standard = (variant ?? (type ? 'standard' : 'business')) === 'standard';
|
|
4
|
+
const hasTitle = title !== undefined && title !== null && title !== false && title !== '';
|
|
5
|
+
const hasFooter = footer !== undefined && footer !== null && footer !== false;
|
|
6
|
+
return <view className={`ui-card ${standard ? 'ui-card-standard' : 'ui-card-business'} ${standard && type === 'rectangle' ? 'ui-card-rectangle' : ''} ${className}`} style={style}>
|
|
7
|
+
{hasTitle || description ? <view className={`ui-card-header ${customTitleClass}`}>
|
|
8
|
+
{hasTitle ? typeof title === 'string' || typeof title === 'number' ? <text className="ui-card-title" text-maxline={standard ? '1' : undefined} text-overflow="ellipsis">{title}</text> : title : null}
|
|
9
|
+
{description ? <text className="ui-card-description">{description}</text> : null}
|
|
10
|
+
</view> : null}
|
|
11
|
+
{standard || children !== undefined && children !== null && children !== false ? <view className={`ui-card-body ${customContentClass}`}>{standard && type === 'rectangle' ? <view className="ui-card-content-line"/> : null}{content(children)}</view> : null}
|
|
12
|
+
{hasFooter ? <view className={`ui-card-footer ${customFooterClass}`}>{standard ? <view className="ui-card-footer-line"/> : null}{content(footer)}</view> : null}
|
|
13
|
+
</view>;
|
|
14
|
+
}
|
|
15
|
+
export function SectionTitle({ eyebrow, title, description }) {
|
|
16
|
+
return <view className="ui-section-title">
|
|
17
|
+
{eyebrow ? <text className="ui-section-eyebrow">{eyebrow}</text> : null}
|
|
18
|
+
<text className="ui-section-heading">{title}</text>
|
|
19
|
+
{description ? <text className="ui-section-description">{description}</text> : null}
|
|
20
|
+
</view>;
|
|
21
|
+
}
|