Skip to content

Commit 5ecf825

Browse files
committed
feat: add wrap div
1 parent 89d3aee commit 5ecf825

File tree

3 files changed

+586
-534
lines changed

3 files changed

+586
-534
lines changed

assets/index.less

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020
align-items: stretch;
2121
justify-items: flex-start;
2222

23-
background-color: rgba(0, 0, 0, 0.04);
2423
border-radius: 2px;
25-
box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.04);
24+
25+
&-wrap {
26+
display: inline-flex;
27+
padding: 2px;
28+
background-color: rgba(0, 0, 0, 0.04);
29+
}
2630

2731
&-item {
2832
position: relative;
@@ -49,6 +53,7 @@
4953

5054
&-label {
5155
z-index: 2;
56+
line-height: 24px;
5257
}
5358

5459
&-input {

src/index.tsx

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ function normalizeOptions(options: SegmentedOptions): SegmentedLabeledOption[] {
6767
const calcThumbStyle = (targetElement: HTMLElement): React.CSSProperties => ({
6868
transform: `translateX(${targetElement.offsetLeft}px)`,
6969
width: targetElement.clientWidth,
70+
height: targetElement.clientHeight,
7071
});
7172

7273
const InternalSegmentedOption: React.FC<{
@@ -261,52 +262,54 @@ const Segmented = React.forwardRef<HTMLDivElement, SegmentedProps>(
261262
const divProps = omit(restProps, ['children']);
262263

263264
return (
264-
<div
265-
{...divProps}
266-
className={classNames(
267-
prefixCls,
268-
{
269-
[`${prefixCls}-rtl`]: direction === 'rtl',
270-
[`${prefixCls}-disabled`]: disabled,
271-
},
272-
className,
273-
)}
274-
ref={mergedRef}
275-
>
276-
<CSSMotion
277-
visible={thumbShow}
278-
motionName={`${prefixCls}-${motionName}`}
279-
motionDeadline={300}
280-
onEnterStart={handleThumbEnterStart}
281-
onEnterActive={handleThumbEnterActive}
282-
onEnterEnd={handleThumbEnterEnd}
265+
<div className={`${prefixCls}-wrap`}>
266+
<div
267+
{...divProps}
268+
className={classNames(
269+
prefixCls,
270+
{
271+
[`${prefixCls}-rtl`]: direction === 'rtl',
272+
[`${prefixCls}-disabled`]: disabled,
273+
},
274+
className,
275+
)}
276+
ref={mergedRef}
283277
>
284-
{({ className: motionClassName, style: motionStyle }) => {
285-
return (
286-
<div
287-
style={motionStyle}
288-
className={classNames(`${prefixCls}-thumb`, motionClassName)}
289-
/>
290-
);
291-
}}
292-
</CSSMotion>
293-
{segmentedOptions.map((segmentedOption) => (
294-
<InternalSegmentedOption
295-
key={segmentedOption.value}
296-
prefixCls={prefixCls}
297-
className={classNames(
298-
segmentedOption.className,
299-
`${prefixCls}-item`,
300-
{
301-
[`${prefixCls}-item-selected`]:
302-
segmentedOption.value === visualSelected,
303-
},
304-
)}
305-
checked={segmentedOption.value === selected}
306-
onChange={handleChange}
307-
{...segmentedOption}
308-
/>
309-
))}
278+
<CSSMotion
279+
visible={thumbShow}
280+
motionName={`${prefixCls}-${motionName}`}
281+
motionDeadline={300}
282+
onEnterStart={handleThumbEnterStart}
283+
onEnterActive={handleThumbEnterActive}
284+
onEnterEnd={handleThumbEnterEnd}
285+
>
286+
{({ className: motionClassName, style: motionStyle }) => {
287+
return (
288+
<div
289+
style={motionStyle}
290+
className={classNames(`${prefixCls}-thumb`, motionClassName)}
291+
/>
292+
);
293+
}}
294+
</CSSMotion>
295+
{segmentedOptions.map((segmentedOption) => (
296+
<InternalSegmentedOption
297+
key={segmentedOption.value}
298+
prefixCls={prefixCls}
299+
className={classNames(
300+
segmentedOption.className,
301+
`${prefixCls}-item`,
302+
{
303+
[`${prefixCls}-item-selected`]:
304+
segmentedOption.value === visualSelected,
305+
},
306+
)}
307+
checked={segmentedOption.value === selected}
308+
onChange={handleChange}
309+
{...segmentedOption}
310+
/>
311+
))}
312+
</div>
310313
</div>
311314
);
312315
},

0 commit comments

Comments
 (0)