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 `disabled` prop of `Slider` (#1199)

白熱25348e92218e
diff --git a/packages/design/src/components/slider/Slider.tsx b/packages/design/src/components/slider/Slider.tsx
index f92e5bc9d3..982242321e 100644
--- a/packages/design/src/components/slider/Slider.tsx
+++ b/packages/design/src/components/slider/Slider.tsx
@@ -39,6 +39,12 @@ export interface ISliderProps {
*/
max?: number;
+ /**
+ * Whether the slider is disabled
+ * @default false
+ */
+ disabled?: boolean;
+
/** The maximum value the slider can slide to
* @default 100
*/
@@ -55,17 +61,21 @@ export interface ISliderProps {
* Slider Component
*/
export function Slider(props: ISliderProps) {
- const { value, min = 0, max = 400, resetPoint = 100, shortcuts, onChange } = props;
+ const { value, min = 0, max = 400, disabled = false, resetPoint = 100, shortcuts, onChange } = props;
const sliderInnerRailRef = useRef<HTMLDivElement>(null);
const { locale } = useContext(ConfigContext);
function handleReset() {
+ if (disabled) return;
+
onChange && onChange(resetPoint);
}
function handleStep(offset: number) {
+ if (disabled) return;
+
let result = value + offset;
if (value + offset <= min) {
result = min;
@@ -87,7 +97,9 @@ export function Slider(props: ISliderProps) {
}, [min, max, resetPoint, value]);
function handleMouseDown(e: React.MouseEvent<HTMLDivElement>) {
+ if (disabled) return;
e.preventDefault();
+
const rail = sliderInnerRailRef.current!;
let isDragging = true;
@@ -132,8 +144,12 @@ export function Slider(props: ISliderProps) {
}
return (
- <div className={styles.slider}>
- <Button type="text" size="small" disabled={value <= min} onClick={() => handleStep(-10)}>
+ <div
+ className={clsx(styles.slider, {
+ [styles.sliderDisabled]: disabled,
+ })}
+ >
+ <Button type="text" size="small" disabled={value <= min || disabled} onClick={() => handleStep(-10)}>
<ReduceSingle />
</Button>
@@ -154,7 +170,7 @@ export function Slider(props: ISliderProps) {
</div>
</div>
- <Button type="text" size="small" disabled={value >= max} onClick={() => handleStep(10)}>
+ <Button type="text" size="small" disabled={value >= max || disabled} onClick={() => handleStep(10)}>
<IncreaseSingle />
</Button>
diff --git a/packages/design/src/components/slider/index.module.less b/packages/design/src/components/slider/index.module.less
index 9a033a371f..70262dabd8 100644
--- a/packages/design/src/components/slider/index.module.less
+++ b/packages/design/src/components/slider/index.module.less
@@ -16,10 +16,51 @@
}
.slider {
+ user-select: none;
display: flex;
gap: var(--margin-xxs);
align-items: center;
+ &-disabled {
+ cursor: not-allowed;
+
+ .slider {
+ &-rail {
+ background-color: rgb(var(--grey-300));
+ }
+
+ &-handle {
+ background-color: rgb(var(--grey-300));
+ box-shadow: none;
+
+ &:hover {
+ cursor: not-allowed;
+ background-color: rgb(var(--grey-300));
+ }
+ }
+
+ &-reset-point {
+ cursor: not-allowed;
+ }
+
+ &-value {
+ &:hover {
+ cursor: not-allowed;
+ background-color: rgb(var(--grey-300));
+ }
+ }
+
+ &-value {
+ pointer-events: none;
+ color: rgb(var(--grey-300));
+
+ &:hover {
+ background-color: transparent;
+ }
+ }
+ }
+ }
+
&-rail {
@padding: (@slider-handle-size / 2);