@doubao-dev/template 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/components/extra-action/index.d.ts +6 -1
- package/dist/components/extra-action/index.js +3 -0
- package/dist/index.d.ts +1 -1
- package/dist/primitives/index.d.ts +1 -0
- package/dist/primitives/index.js +1 -0
- package/dist/primitives/stepper/index.d.ts +5 -0
- package/dist/primitives/stepper/index.js +33 -0
- package/dist/primitives/stepper/styles.css +1 -0
- package/dist/primitives/stepper/types.d.ts +12 -0
- package/dist/primitives/stepper/types.js +0 -0
- package/dist/utils/icons.d.ts +2 -1
- package/dist/utils/icons.js +8 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,7 +43,7 @@ export default function ProductCard() {
|
|
|
43
43
|
| 人工确认选项 | [AskHumanCard](../../../docs/templates/ask-human-card.mdx) |
|
|
44
44
|
| 多种内容组成一张卡片 | [CompositeCard](../../../docs/templates/composite-card.mdx) |
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
标题、标签、价格、选项和数量调节组件见 [Primitives](../../../docs/templates/shared-components.mdx#primitives)。
|
|
47
47
|
|
|
48
48
|
## 使用约定
|
|
49
49
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { TouchEvent } from '@lynx-js/types';
|
|
2
2
|
import { type ReactNode } from 'react';
|
|
3
|
+
import { type StepperProps } from '../../primitives/stepper/index.js';
|
|
3
4
|
import './styles.scss';
|
|
4
5
|
/** 模板右侧控件:按钮。 */
|
|
5
6
|
export interface TemplateExtraActionButton {
|
|
@@ -23,6 +24,10 @@ export interface TemplateExtraActionAdd {
|
|
|
23
24
|
/** 点击添加控件时触发。 */
|
|
24
25
|
onClick?: (event?: TouchEvent) => void;
|
|
25
26
|
}
|
|
27
|
+
/** 模板右侧控件:数量调节器。 */
|
|
28
|
+
export interface TemplateExtraActionStepper extends StepperProps {
|
|
29
|
+
type: 'stepper';
|
|
30
|
+
}
|
|
26
31
|
/** 模板右侧控件:开关。受控用法,必须传入 checked。 */
|
|
27
32
|
export interface TemplateExtraActionSwitch {
|
|
28
33
|
type: 'switch';
|
|
@@ -46,7 +51,7 @@ export interface TemplateExtraActionPlayback {
|
|
|
46
51
|
onToggle?: (playing: boolean) => void;
|
|
47
52
|
}
|
|
48
53
|
/** 模板右侧标准控件配置(判别联合)。 */
|
|
49
|
-
export type TemplateExtraAction = TemplateExtraActionButton | TemplateExtraActionAdd | TemplateExtraActionSwitch | TemplateExtraActionPlayback;
|
|
54
|
+
export type TemplateExtraAction = TemplateExtraActionButton | TemplateExtraActionAdd | TemplateExtraActionStepper | TemplateExtraActionSwitch | TemplateExtraActionPlayback;
|
|
50
55
|
export interface TemplateExtraActionClassNames {
|
|
51
56
|
button?: string;
|
|
52
57
|
switch?: string;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Button, Switch, useTheme } from "@byted-doubao-apps/components";
|
|
2
2
|
import { clsx } from "clsx";
|
|
3
3
|
import { useState } from "react";
|
|
4
|
+
import { Stepper } from "../../primitives/stepper/index.js";
|
|
4
5
|
import { getTemplateAddIconContent, getTemplateAddLoadingIconContent, getTemplatePlaybackIconContent } from "../../utils/icons.js";
|
|
5
6
|
import "./styles.css";
|
|
6
7
|
function stopTemplateExtraActionTap() {}
|
|
@@ -42,6 +43,8 @@ function renderTemplateExtraAction(action, classNames = {}) {
|
|
|
42
43
|
return <Button className={clsx('doubao-template-extra-action-button', classNames.button)} type="default" text={action.text} disabled={action.disabled} loading={action.loading} onClick={action.onClick}/>;
|
|
43
44
|
case 'add':
|
|
44
45
|
return <TemplateAddAction {...action}/>;
|
|
46
|
+
case 'stepper':
|
|
47
|
+
return <Stepper value={action.value} min={action.min} max={action.max} onChange={action.onChange}/>;
|
|
45
48
|
case 'switch':
|
|
46
49
|
return <Switch className={classNames.switch} checked={action.checked} disabled={action.disabled} onChange={action.onChange}/>;
|
|
47
50
|
case 'playback':
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { ContentCard, type ContentCardItem, type ContentCardProps } from './cont
|
|
|
2
2
|
export { CompositeCard, type CompositeCardContentSection, type CompositeCardOptionGroupSection, type CompositeCardProps, type CompositeCardSection, type CompositeCardTransitSection } from './composite-card/index.js';
|
|
3
3
|
export type { TemplateCardHeaderProps } from './components/header/index.js';
|
|
4
4
|
export type { TemplateCardFooterActionButton, TemplateCardFooterProps } from './components/footer/index.js';
|
|
5
|
-
export type { TemplateExtraAction, TemplateExtraActionAdd, TemplateExtraActionButton, TemplateExtraActionPlayback, TemplateExtraActionSwitch } from './components/extra-action/index.js';
|
|
5
|
+
export type { TemplateExtraAction, TemplateExtraActionAdd, TemplateExtraActionButton, TemplateExtraActionPlayback, TemplateExtraActionStepper, TemplateExtraActionSwitch } from './components/extra-action/index.js';
|
|
6
6
|
export { AskHumanCard, type AskHumanCardArrowPosition, type AskHumanCardItem, type AskHumanCardProps } from './ask-human-card/index.js';
|
|
7
7
|
export { CheckoutCard, type CheckoutCardFeeItem, type CheckoutCardInfoItem, type CheckoutCardProductItem, type CheckoutCardProps } from './checkout-card/index.js';
|
|
8
8
|
export { PriceActionCard, type PriceActionCardInfoRow, type PriceActionCardItem, type PriceActionCardProps } from './price-action-card/index.js';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { Icon, type IconName, type IconProps } from './icon/index.js';
|
|
2
2
|
export { OptionGroup, type OptionGroupItem, type OptionGroupLargeItem, type OptionGroupMediumItem, type OptionGroupProps, type OptionGroupSize, type OptionGroupText, type OptionGroupValue } from './option-group/index.js';
|
|
3
3
|
export { Price, type PricePrefixTone, type PriceProps, type PriceTone, type PriceValue } from './price/index.js';
|
|
4
|
+
export { Stepper, type StepperProps } from './stepper/index.js';
|
|
4
5
|
export { Tag, type TagProps, type TagTone, type TagValue } from './tag/index.js';
|
|
5
6
|
export { Title, type TitleMaxLines, type TitleProps, type TitleValue } from './title/index.js';
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/primitives/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { Icon } from "./icon/index.js";
|
|
2
2
|
export { OptionGroup } from "./option-group/index.js";
|
|
3
3
|
export { Price } from "./price/index.js";
|
|
4
|
+
export { Stepper } from "./stepper/index.js";
|
|
4
5
|
export { Tag } from "./tag/index.js";
|
|
5
6
|
export { Title } from "./title/index.js";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useTheme, useThemeClassName } from "@byted-doubao-apps/components";
|
|
2
|
+
import { clsx } from "clsx";
|
|
3
|
+
import { getTemplateAddIconContent, getTemplateMinusIconContent } from "../../utils/icons.js";
|
|
4
|
+
import "./styles.css";
|
|
5
|
+
function Stepper({ value, min = 0, max, onChange }) {
|
|
6
|
+
const theme = useTheme();
|
|
7
|
+
const themedClassName = useThemeClassName();
|
|
8
|
+
const iconColor = 'dark' === theme ? '#cccccc' : '#666666';
|
|
9
|
+
const addIconContent = getTemplateAddIconContent(iconColor, 12);
|
|
10
|
+
const minusIconContent = getTemplateMinusIconContent(iconColor);
|
|
11
|
+
const cannotDecrease = value <= min;
|
|
12
|
+
const cannotIncrease = null != max && value >= max;
|
|
13
|
+
const handleDecrease = (event)=>{
|
|
14
|
+
if (!cannotDecrease) onChange?.(Math.max(value - 1, min), event);
|
|
15
|
+
};
|
|
16
|
+
const handleIncrease = (event)=>{
|
|
17
|
+
if (!cannotIncrease) onChange?.(null == max ? value + 1 : Math.min(value + 1, max), event);
|
|
18
|
+
};
|
|
19
|
+
return <view className={clsx('doubao-stepper', themedClassName)}>
|
|
20
|
+
<view className="doubao-stepper__button" catchtap={cannotDecrease ? void 0 : handleDecrease}>
|
|
21
|
+
<svg className={clsx('doubao-stepper__icon', cannotDecrease && 'doubao-stepper__icon--disabled')} content={minusIconContent}/>
|
|
22
|
+
</view>
|
|
23
|
+
<view className="doubao-stepper__value">
|
|
24
|
+
<text className="doubao-stepper__value-text" text-maxline="1">
|
|
25
|
+
{value}
|
|
26
|
+
</text>
|
|
27
|
+
</view>
|
|
28
|
+
<view className="doubao-stepper__button" catchtap={cannotIncrease ? void 0 : handleIncrease}>
|
|
29
|
+
<svg className={clsx('doubao-stepper__icon', cannotIncrease && 'doubao-stepper__icon--disabled')} content={addIconContent}/>
|
|
30
|
+
</view>
|
|
31
|
+
</view>;
|
|
32
|
+
}
|
|
33
|
+
export { Stepper };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.doubao-stepper{display:flex;flex-direction:row;align-items:center;width:92px;height:24px;flex-shrink:0}.doubao-stepper__button{display:flex;align-items:center;justify-content:center;width:24px;height:24px;flex-shrink:0;background-color:var(--bg-base-4-overlay);border-radius:100px}.doubao-stepper__icon{width:12px;height:12px;flex-shrink:0}.doubao-stepper__icon--disabled{opacity:.3}.doubao-stepper__value{display:flex;align-items:center;justify-content:center;box-sizing:border-box;width:44px;height:24px;padding:0 4px;flex-shrink:0;overflow:hidden}.doubao-stepper__value-text{display:block;width:100%;min-width:0;overflow:hidden;color:var(--neutral-100);font-family:"PingFang SC",sans-serif;font-size:16px;font-style:normal;font-weight:500;line-height:24px;text-align:center;text-overflow:ellipsis;white-space:nowrap}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TouchEvent } from '@lynx-js/types';
|
|
2
|
+
export interface StepperProps {
|
|
3
|
+
/** 当前数量。组件受控,需在 onChange 中更新。 */
|
|
4
|
+
value: number;
|
|
5
|
+
/** 可选的最小值;达到时禁用减号。@defaultValue 0 */
|
|
6
|
+
min?: number;
|
|
7
|
+
/** 可选的最大值;达到时禁用加号。 */
|
|
8
|
+
max?: number;
|
|
9
|
+
/** 点击可用的加号或减号时返回下一数量。 */
|
|
10
|
+
onChange?: (value: number, event: TouchEvent) => void;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=types.d.ts.map
|
|
File without changes
|
package/dist/utils/icons.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export declare function getTemplateAddIconContent(color: string): string;
|
|
1
|
+
export declare function getTemplateAddIconContent(color: string, size?: number): string;
|
|
2
|
+
export declare function getTemplateMinusIconContent(color: string): string;
|
|
2
3
|
export declare function getTemplateAddLoadingIconContent(color: string): string;
|
|
3
4
|
export declare function getTemplatePlaybackIconContent(playing: boolean, progress: number | undefined, color: string): string;
|
|
4
5
|
//# sourceMappingURL=icons.d.ts.map
|
package/dist/utils/icons.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
function getTemplateAddIconContent(color) {
|
|
2
|
-
return `<svg width="
|
|
1
|
+
function getTemplateAddIconContent(color, size = 14) {
|
|
2
|
+
return `<svg width="${size}" height="${size}" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
3
3
|
<path d="M7.00065 1.021C7.4839 1.021 7.87565 1.41275 7.87565 1.896V6.12231H12.1048C12.5881 6.12231 12.9798 6.51407 12.9798 6.99731C12.9797 7.48044 12.588 7.87231 12.1048 7.87231H7.87565V12.1043C7.87559 12.5875 7.48386 12.9793 7.00065 12.9793C6.51744 12.9793 6.12571 12.5875 6.12565 12.1043V7.87231H1.89648C1.41338 7.87225 1.02163 7.4804 1.02148 6.99731C1.02148 6.5141 1.41329 6.12238 1.89648 6.12231H6.12565V1.896C6.12565 1.41275 6.5174 1.021 7.00065 1.021Z" fill="${color}"/>
|
|
4
4
|
</svg>`;
|
|
5
5
|
}
|
|
6
|
+
function getTemplateMinusIconContent(color) {
|
|
7
|
+
return `<svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
8
|
+
<path d="M10.1836 5.25C10.5978 5.25 10.9336 5.58579 10.9336 6C10.9336 6.41421 10.5978 6.75 10.1836 6.75H1.81641C1.40219 6.75 1.06641 6.41421 1.06641 6C1.06641 5.58579 1.40219 5.25 1.81641 5.25H10.1836Z" fill="${color}"/>
|
|
9
|
+
</svg>`;
|
|
10
|
+
}
|
|
6
11
|
function getTemplateAddLoadingIconContent(color) {
|
|
7
12
|
const opacities = [
|
|
8
13
|
1,
|
|
@@ -44,4 +49,4 @@ ${renderTemplatePlaybackProgress(progress, color)}
|
|
|
44
49
|
${getTemplatePauseIconPath(color)}
|
|
45
50
|
</svg>`;
|
|
46
51
|
}
|
|
47
|
-
export { getTemplateAddIconContent, getTemplateAddLoadingIconContent, getTemplatePlaybackIconContent };
|
|
52
|
+
export { getTemplateAddIconContent, getTemplateAddLoadingIconContent, getTemplateMinusIconContent, getTemplatePlaybackIconContent };
|