This commit is contained in:
Bowen Tan 2022-01-26 18:19:12 +08:00
parent 64750873e1
commit 7c8731405b
8 changed files with 54 additions and 39 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@sunmao-ui/arco-lib",
"version": "0.0.1",
"version": "0.0.2",
"homepage": "https://github.com/webzard-io/sunmao-ui-arco-lib",
"license": "MIT",
"publishConfig": {
@ -33,9 +33,11 @@
"@arco-design/web-react": "^2.26.1",
"@emotion/css": "^11.5.0",
"@sinclair/typebox": "^0.21.2",
"@sunmao-ui/core": "^0.3.5",
"@sunmao-ui/runtime": "^0.3.9",
"@sunmao-ui/core": "^0.3.6",
"@sunmao-ui/runtime": "^0.3.10",
"eslint-plugin-react-hooks": "^4.3.0",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
@ -43,6 +45,8 @@
"@sunmao-ui/editor": "^0.3.9",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"@types/lodash": "^4.14.170",
"@types/lodash-es": "^4.17.5",
"@typescript-eslint/eslint-plugin": "^4.31.1",
"@typescript-eslint/parser": "^4.31.1",
"@vitejs/plugin-react": "^1.0.0",

View File

@ -8,6 +8,7 @@ import {
CascaderValueSchema,
} from "../generated/types/Cascader";
import { useState, useEffect } from "react";
import { isArray } from "lodash-es";
const CascaderPropsSchema = Type.Object(BaseCascaderPropsSchema);
const CascaderStateSchema = Type.Object({
@ -67,7 +68,7 @@ const CascaderImpl: ComponentImpl<Static<typeof CascaderPropsSchema>> = (
const { multiple, placeholder, ...cProps } = getComponentProps(props);
const { mergeState, slotsElements, customStyle, className, options } = props;
const content = slotsElements.content && slotsElements.content[0];
const content = isArray(slotsElements.content) ? slotsElements.content[0] : slotsElements.content;
const mode: "multiple" | undefined = multiple ? "multiple" : undefined;

View File

@ -2,14 +2,14 @@ import {
Checkbox as BaseCheckbox,
} from '@arco-design/web-react';
import { Type, Static } from '@sinclair/typebox';
import { ComponentImpl, implementRuntimeComponent, observer } from '@sunmao-ui/runtime';
import { ComponentImpl, implementRuntimeComponent } from '@sunmao-ui/runtime';
import {
CheckboxPropsSchema as BaseCheckboxPropsSchema,
CheckboxOptionSchema as BaseCheckboxOptionSchema
} from '../generated/types/Checkbox';
import { FALLBACK_METADATA, getComponentProps } from "../sunmao-helper";
import { css, cx } from '@emotion/css';
import { useState, useEffect, useMemo } from 'react';
import { useState, useEffect, useMemo, useCallback } from 'react';
const CheckboxPropsSchema = Type.Object({
...BaseCheckboxPropsSchema,
@ -20,7 +20,7 @@ const CheckboxStateSchema = Type.Object({
isCheckAll: Type.Boolean()
});
const CheckboxImpl: ComponentImpl<Static<typeof CheckboxPropsSchema>> = observer((props)=> {
const CheckboxImpl: ComponentImpl<Static<typeof CheckboxPropsSchema>> = props => {
const {
mergeState,
subscribeMethods,
@ -60,7 +60,7 @@ const CheckboxImpl: ComponentImpl<Static<typeof CheckboxPropsSchema>> = observer
});
callbackMap?.onChange?.();
};
const checkAll = ()=> {
const checkAll = useCallback(()=> {
const newCheckedValues = enabledOptions.map(({value})=> value);
setCheckedValues(newCheckedValues);
@ -68,14 +68,14 @@ const CheckboxImpl: ComponentImpl<Static<typeof CheckboxPropsSchema>> = observer
checkedValues: newCheckedValues,
isCheckAll: true
});
};
const uncheckAll = ()=> {
}, [enabledOptions, mergeState]);
const uncheckAll = useCallback(()=> {
setCheckedValues([]);
mergeState({
checkedValues: [],
isCheckAll: false
});
};
}, [mergeState]);
const onCheckAll = ()=> {
if (checkedValues.length !== enabledOptions.length) {
checkAll();
@ -122,7 +122,7 @@ const CheckboxImpl: ComponentImpl<Static<typeof CheckboxPropsSchema>> = observer
checkAll,
uncheckAll,
});
}, [subscribeMethods, mergeState, checkedValues, options]);
}, [subscribeMethods, mergeState, checkedValues, options, checkAll, uncheckAll]);
const CheckAll = showCheckAll ? (
<BaseCheckbox
@ -170,9 +170,9 @@ const CheckboxImpl: ComponentImpl<Static<typeof CheckboxPropsSchema>> = observer
{CheckboxList}
</>
);
});
};
const exampleProperties: Static<typeof CheckboxPropsSchema> = {
const exampleProperties = {
className: 'checkbox',
options: [],
direction: 'horizontal',
@ -192,20 +192,20 @@ const options = {
spec: {
properties: CheckboxPropsSchema,
state: CheckboxStateSchema,
methods: {
methods: Type.Object({
setCheckedValues: Type.Object({
values: Type.Array(Type.String())
}),
checkAll: void 0,
uncheckAll: void 0,
checkAll: Type.Object({}),
uncheckAll: Type.Object({}),
toggleValues: Type.Object({
values: BaseCheckboxOptionSchema
})
},
}),
styleSlots: ['content'],
slots:[],
events: ['onChange']
}
};
export const Checkbox = implementRuntimeComponent(options)(CheckboxImpl);
export const Checkbox = implementRuntimeComponent(options)(CheckboxImpl as any);

View File

@ -5,6 +5,7 @@ import { Type, Static } from "@sinclair/typebox";
import { FALLBACK_METADATA, getComponentProps } from "../sunmao-helper";
import { PopoverPropsSchema as BasePopoverPropsSchema } from "../generated/types/Popover";
import { useEffect, useState } from "react";
import { isArray } from "lodash-es";
const PopoverPropsSchema = Type.Object(BasePopoverPropsSchema);
const PopoverStateSchema = Type.Object({
@ -37,7 +38,7 @@ const PopoverImpl: ComponentImpl<Static<typeof PopoverPropsSchema>> = (
}, [popupVisible, mergeState]);
// TODO only support arco componets slot now (same as Tooltip)
const content = slotsElements.content && slotsElements.content[0];
const content = isArray(slotsElements.content) ? slotsElements.content[0] : slotsElements.content;
return controlled ? (
<BasePopover

View File

@ -7,6 +7,7 @@ import {
StepsPropsSchema as BaseStepsPropsSchema,
StepItemSchema,
} from "../generated/types/Steps";
import { isArray } from "lodash-es";
const StepsPropsSchema = Type.Object(BaseStepsPropsSchema);
const StepsStateSchema = Type.Object({});
@ -23,7 +24,7 @@ const StepsImpl: ComponentImpl<Static<typeof StepsPropsSchema>> = (props) => {
items.map((stepItem: StepItem, idx: number) => {
return (
<BaseSteps.Step
icon={slotsElements.icons && slotsElements.icons[idx]}
icon={isArray(slotsElements.icons) && slotsElements.icons[idx]}
key={idx}
title={stepItem.title}
description={stepItem.description}

View File

@ -5,6 +5,7 @@ import { Type, Static } from "@sinclair/typebox";
import { FALLBACK_METADATA, getComponentProps } from "../sunmao-helper";
import { TooltipPropsSchema as BaseTooltipPropsSchema } from "../generated/types/Tooltip";
import { useEffect, useState } from "react";
import { isArray } from "lodash-es";
const TooltipPropsSchema = Type.Object(BaseTooltipPropsSchema);
const TooltipStateSchema = Type.Object({
@ -40,7 +41,7 @@ const TooltipImpl: ComponentImpl<Static<typeof TooltipPropsSchema>> = (
// two components in the array will be wrapped by span respectively
// and arco does not support `array.length===1` think it is a bug
// TODO only support arco componets slot now
const content = slotsElements.content && slotsElements.content[0];
const content = isArray(slotsElements.content) ? slotsElements.content[0] : slotsElements.content;
return controlled ? (
<BaseTooltip

File diff suppressed because one or more lines are too long

View File

@ -1065,30 +1065,30 @@
integrity sha512-YeGOsWyjmGS26VxfvxbDgO7In4em8riCI5hEe/NnjM72ifoLQNUeHxwFNufXVIcaaPEK4fCV+fYoLKgmpPKjsA==
"@sunmao-ui/chakra-ui-lib@^0.1.3":
version "0.1.3"
resolved "https://registry.yarnpkg.com/@sunmao-ui/chakra-ui-lib/-/chakra-ui-lib-0.1.3.tgz#704ffb9b85cc62c8adc8e58a0af069cbaef8d6c5"
integrity sha512-y0aDsE/xcSlUegQq+Pq8P3zidG76EUCQiO61fhPOM8q0btm0Hy5vc9yq6ChIdSF61axjiASM/FuQUemhUB015g==
version "0.1.4"
resolved "https://registry.yarnpkg.com/@sunmao-ui/chakra-ui-lib/-/chakra-ui-lib-0.1.4.tgz#1c549d8d506d49f6cef9e338e37f30456f8642e7"
integrity sha512-melhV4nvPjcD/qUuhyz8V5v4rVhIdpf3FoXMHH/kLd33E5ruh6Z2sTasf1Sm69PbQZo33LCq0v+iRN6/FR/AAA==
dependencies:
"@chakra-ui/icons" "^1.0.15"
"@chakra-ui/react" "^1.7.1"
"@sinclair/typebox" "^0.21.2"
"@sunmao-ui/core" "^0.3.5"
"@sunmao-ui/runtime" "^0.3.9"
"@sunmao-ui/core" "^0.3.6"
"@sunmao-ui/runtime" "^0.3.10"
chakra-react-select "^1.3.2"
framer-motion "^4"
lodash-es "^4.17.21"
react "^17.0.0"
react-dom "^17.0.0"
"@sunmao-ui/core@^0.3.5":
version "0.3.5"
resolved "https://registry.yarnpkg.com/@sunmao-ui/core/-/core-0.3.5.tgz#d6d08d151b4324cec3ed9f66092c5902f59941c4"
integrity sha512-aH6NOCgH+C7BGbJqSmi9J52Ge+wp0GTjLmVTMEQ/YtDAd84Bx7B4z9ZgFM+0VkuNJ2PyHT7F8i7uYZYVyxkCsg==
"@sunmao-ui/core@^0.3.5", "@sunmao-ui/core@^0.3.6":
version "0.3.6"
resolved "https://registry.yarnpkg.com/@sunmao-ui/core/-/core-0.3.6.tgz#236e448db7881773c89f6a38c1669c22e9c5ee05"
integrity sha512-WURF0l7FdweCJUiEas5rseZlUIgLPaJSQx9tTvJcUqao3W9RxWZ5tfsUPMx+9vxb4xyfFEruiD9JrpespgeIrg==
dependencies:
"@types/json-schema" "^7.0.7"
lodash-es "^4.17.21"
"@sunmao-ui/editor@^0.3.9":
"@sunmao-ui/editor@0.3.9":
version "0.3.9"
resolved "https://registry.yarnpkg.com/@sunmao-ui/editor/-/editor-0.3.9.tgz#e96a142cd8379f56d65c87fea6a7ceca4f8e891e"
integrity sha512-eRw6vV65jwsTm/bpEYkJgez4RhHdT6MhxZSco5/+Sq6gfpoR4yW3NcmAcoSgIxrwJkUQ5OMjGKHBxGqRHc/FUA==
@ -1111,15 +1111,15 @@
react "^17.0.2"
react-dom "^17.0.2"
"@sunmao-ui/runtime@^0.3.9":
version "0.3.9"
resolved "https://registry.yarnpkg.com/@sunmao-ui/runtime/-/runtime-0.3.9.tgz#d984aa648c66b1576459a772dd47f0da2f14b43f"
integrity sha512-te+dJudbJDS2shp0Z4LaQzcayYH6cZhDIi0Hh7z/Ofn9F/cGY5A3e2RFwz9hu/M52aLLT4fDym5PEKWkQJWrVA==
"@sunmao-ui/runtime@^0.3.10", "@sunmao-ui/runtime@^0.3.9":
version "0.3.10"
resolved "https://registry.yarnpkg.com/@sunmao-ui/runtime/-/runtime-0.3.10.tgz#e3659569cb9009a3a8b78fd890cd41a63a6182ee"
integrity sha512-Aiiim/4tsjZVJ6JFyhwfHwdEf0QwiHxMwYY7GjpYGDEm7a9DzOFyT+3t06TJDygHibF1Fezd+1EgalsHbS2L2g==
dependencies:
"@emotion/css" "^11.7.1"
"@emotion/styled" "^11"
"@sinclair/typebox" "^0.21.2"
"@sunmao-ui/core" "^0.3.5"
"@sunmao-ui/core" "^0.3.6"
"@vue/reactivity" "^3.1.5"
"@vue/shared" "^3.2.20"
copy-to-clipboard "^3.3.1"
@ -1156,6 +1156,13 @@
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.9.tgz#97edc9037ea0c38585320b28964dde3b39e4660d"
integrity sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ==
"@types/lodash-es@^4.17.5":
version "4.17.5"
resolved "https://registry.yarnpkg.com/@types/lodash-es/-/lodash-es-4.17.5.tgz#1c3fdd16849d84aea43890b1c60da379fb501353"
integrity sha512-SHBoI8/0aoMQWAgUHMQ599VM6ZiSKg8sh/0cFqqlQQMyY9uEplc0ULU5yQNzcvdR4ZKa0ey8+vFmahuRbOCT1A==
dependencies:
"@types/lodash" "*"
"@types/lodash.mergewith@4.6.6":
version "4.6.6"
resolved "https://registry.yarnpkg.com/@types/lodash.mergewith/-/lodash.mergewith-4.6.6.tgz#c4698f5b214a433ff35cb2c75ee6ec7f99d79f10"
@ -1163,7 +1170,7 @@
dependencies:
"@types/lodash" "*"
"@types/lodash@*":
"@types/lodash@*", "@types/lodash@^4.14.170":
version "4.14.178"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.178.tgz#341f6d2247db528d4a13ddbb374bcdc80406f4f8"
integrity sha512-0d5Wd09ItQWH1qFbEyQ7oTQ3GZrMfth5JkbN3EvTKLXcHLRDSXeLnlvlOn0wvxVIwK5o2M8JzP/OWz7T3NRsbw==