From 9bcc0b05ee8378e8c37f59288049e81975a59ec0 Mon Sep 17 00:00:00 2001 From: 13659257719 <819781841@qq.com> Date: Thu, 2 Nov 2023 11:04:18 +0800 Subject: [PATCH] =?UTF-8?q?[inula-dev-tools]=20Search=20=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/Search.less | 18 +++++++ .../inula-dev-tools/src/components/Search.tsx | 44 +++++++++++++++++ .../src/components/SizeObserver.tsx | 48 +++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 packages/inula-dev-tools/src/components/Search.less create mode 100644 packages/inula-dev-tools/src/components/Search.tsx diff --git a/packages/inula-dev-tools/src/components/Search.less b/packages/inula-dev-tools/src/components/Search.less new file mode 100644 index 00000000..72752465 --- /dev/null +++ b/packages/inula-dev-tools/src/components/Search.less @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2023 Huawei Technologies Co.,Ltd. + * + * openInula is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +.search { + width: 100%; +} diff --git a/packages/inula-dev-tools/src/components/Search.tsx b/packages/inula-dev-tools/src/components/Search.tsx new file mode 100644 index 00000000..ea1b48c8 --- /dev/null +++ b/packages/inula-dev-tools/src/components/Search.tsx @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2023 Huawei Technologies Co.,Ltd. + * + * openInula is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +import styles from './Search.less'; + +interface SearchProps { + onKeyUp: () => void; + onChange: (event: any) => void; + value: string; +} + +export default function Search(props: SearchProps) { + const { onChange, value, onKeyUp } = props; + const handleChange = event => { + onChange(event.target.value); + }; + const handleKeyUp = event => { + if (event.key === 'Enter') { + onKeyUp(); + } + }; + + return ( + + ); +} diff --git a/packages/inula-dev-tools/src/components/SizeObserver.tsx b/packages/inula-dev-tools/src/components/SizeObserver.tsx index e69de29b..32d92058 100644 --- a/packages/inula-dev-tools/src/components/SizeObserver.tsx +++ b/packages/inula-dev-tools/src/components/SizeObserver.tsx @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023 Huawei Technologies Co.,Ltd. + * + * openInula is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * + * http://license.coscl.org.cn/MulanPSL2 + * + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +import { useEffect, useState, useRef } from 'openinula'; +import { addResizeListener, removeResizeListener } from './resizeEvent'; + +export function SizeObserver(props) { + const { children, ...rest } = props; + const containerRef = useRef(); + const [size, setSize] = useState<{ width: number; height: number }>(); + const notifyChild = (element) => { + setSize({ + width: element.offsetWidth, + height: element.offsetHeight, + }); + }; + + useEffect(() => { + const element = containerRef.current!; + setSize({ + width: element.offsetWidth, + height: element.offsetHeight, + }); + addResizeListener(element, notifyChild); + return () => { + removeResizeListener(element, notifyChild); + }; + }, []); + const myChild = size ? children(size.width, size.height) : null; + + return ( +
+ {myChild} +
+ ); +}