Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

feat(design): add grouping support to the `Select` (#586)

白熱f573876e55a8
diff --git a/packages/design/src/components/input-number/index.module.less b/packages/design/src/components/input-number/index.module.less
index 4a7101ca74..d270f84809 100644
--- a/packages/design/src/components/input-number/index.module.less
+++ b/packages/design/src/components/input-number/index.module.less
@@ -1,12 +1,12 @@
.input-number {
display: inline-block;
- height: 26px;
+ height: 34px;
margin: 0;
padding: 0;
font-size: 12px;
- line-height: 26px;
+ line-height: 34px;
vertical-align: middle;
background-color: rgb(var(--bg-color-secondary));
@@ -69,7 +69,7 @@
height: 100%;
padding: 0;
- line-height: 26px;
+ line-height: 34px;
color: rgb(var(--text-color));
text-align: center;
@@ -86,7 +86,7 @@
flex-direction: column;
width: 20px;
- height: 100%;
+ height: 34px;
border-left: 1px solid rgb(var(--border-color));
diff --git a/packages/design/src/components/select/Select.stories.tsx b/packages/design/src/components/select/Select.stories.tsx
index 52719c6c42..c057681e64 100644
--- a/packages/design/src/components/select/Select.stories.tsx
+++ b/packages/design/src/components/select/Select.stories.tsx
@@ -14,7 +14,7 @@ const meta: Meta<typeof Select> = {
export default meta;
-export const Playground = {
+export const SelectBasic = {
render() {
const [value, setValue] = useState('');
@@ -31,3 +31,47 @@ export const Playground = {
return <Select value={value} options={options} onChange={handleChange} />;
},
};
+
+export const SelectGroup = {
+ render() {
+ const [value, setValue] = useState('');
+
+ const options = [
+ { label: 'Option 1', value: 'option1' },
+ {
+ options: [
+ {
+ label: 'Option 2-2',
+ value: 'option22',
+ },
+ {
+ label: 'Option 2-3',
+ value: 'option23',
+ },
+ ],
+ },
+ {
+ options: [
+ {
+ label: (
+ <span>
+ Option 3-2 <strong>xxx</strong>
+ </span>
+ ),
+ value: 'option32',
+ },
+ {
+ label: 'Option 3-3',
+ value: 'option33',
+ },
+ ],
+ },
+ ];
+
+ function handleChange(value: string | number | boolean) {
+ setValue(value as string);
+ }
+
+ return <Select value={value} options={options} onChange={handleChange} />;
+ },
+};
diff --git a/packages/design/src/components/select/Select.tsx b/packages/design/src/components/select/Select.tsx
index 3fc68997b9..88b0046067 100644
--- a/packages/design/src/components/select/Select.tsx
+++ b/packages/design/src/components/select/Select.tsx
@@ -1,9 +1,16 @@
+import { MoreDownSingle } from '@univerjs/icons';
import RcSelect from 'rc-select';
import React, { useContext } from 'react';
import { ConfigContext } from '../config-provider/ConfigProvider';
import styles from './index.module.less';
+interface IOption {
+ label?: string | React.ReactNode;
+ value?: string;
+ options?: IOption[];
+}
+
export interface ISelectProps {
/**
* The value of select
@@ -14,10 +21,7 @@ export interface ISelectProps {
* The options of select
* @default []
*/
- options?: Array<{
- label: string;
- value: string;
- }>;
+ options?: IOption[];
/**
* The callback function that is triggered when the value is changed
@@ -37,7 +41,8 @@ export function Select(props: ISelectProps) {
options={options}
value={value}
menuItemSelectedIcon={null}
+ suffixIcon={<MoreDownSingle />}
onChange={onChange}
- ></RcSelect>
+ />
);
}
diff --git a/packages/design/src/components/select/index.module.less b/packages/design/src/components/select/index.module.less
index 727518e1cf..75e891cff8 100644
--- a/packages/design/src/components/select/index.module.less
+++ b/packages/design/src/components/select/index.module.less
@@ -184,9 +184,18 @@
.@{select-prefix}-arrow {
pointer-events: none;
+
position: absolute;
top: 0;
- right: 5px;
+ right: var(--margin-sm);
+
+ display: flex;
+ align-items: center;
+
+ height: 100%;
+
+ font-size: var(--font-size-xxs);
+ color: rgb(var(--text-color-secondary));
&-icon::after {
content: '';
@@ -230,22 +239,29 @@
// =============== Option ================
&-item {
+ cursor: pointer;
padding: var(--padding-sm) var(--padding-base);
font-size: var(--font-size-sm);
// >>> Group
&-group {
- font-size: 80%;
- font-weight: bold;
- color: #999;
+ // font-size: 80%;
+ // font-weight: bold;
+ // color: #999;
+ padding: 0;
+
+ &:not(:first-child) {
+ border-top: 1px solid rgb(var(--border-color));
+ }
}
// >>> Option
&-option {
position: relative;
+ transition: all 0.15s;
&-grouped {
- padding-left: 24px;
+ // padding-left: 24px;
}
.@{select-prefix}-item-option-state {