Skip to content

feat: add wrap div #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions assets/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@
}

.@{segmented-prefix-cls} {
position: relative;
display: inline-block;
padding: 2px;
background-color: rgba(0, 0, 0, 0.04);

display: inline-flex;
align-items: stretch;
justify-items: flex-start;
&-group {
position: relative;
display: flex;
align-items: stretch;
justify-items: flex-start;

background-color: rgba(0, 0, 0, 0.04);
border-radius: 2px;
box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.04);
width: 100%;
border-radius: 2px;
}

&-item {
position: relative;
Expand All @@ -49,6 +53,7 @@

&-label {
z-index: 2;
line-height: 24px;
}

&-input {
Expand Down
65 changes: 34 additions & 31 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as React from 'react';
import classNames from 'classnames';
// import CSSMotion from 'rc-motion';
import useMergedState from 'rc-util/lib/hooks/useMergedState';
import { composeRef } from 'rc-util/lib/ref';
import omit from 'rc-util/lib/omit';

import MotionThumb from './MotionThumb';

export type SegmentedValue = string | number;
Expand Down Expand Up @@ -178,38 +178,41 @@ const Segmented = React.forwardRef<HTMLDivElement, SegmentedProps>(
)}
ref={mergedRef}
>
<MotionThumb
prefixCls={prefixCls}
value={rawValue}
containerRef={containerRef}
motionName={`${prefixCls}-${motionName}`}
getValueIndex={(val) =>
segmentedOptions.findIndex((n) => n.value === val)
}
onMotionStart={() => {
setThumbShow(true);
}}
onMotionEnd={() => {
setThumbShow(false);
}}
/>
{segmentedOptions.map((segmentedOption) => (
<InternalSegmentedOption
key={segmentedOption.value}
<div className={`${prefixCls}-group`}>
<MotionThumb
prefixCls={prefixCls}
className={classNames(
segmentedOption.className,
`${prefixCls}-item`,
{
[`${prefixCls}-item-selected`]:
segmentedOption.value === rawValue && !thumbShow,
},
)}
checked={segmentedOption.value === rawValue}
onChange={handleChange}
{...segmentedOption}
value={rawValue}
containerRef={containerRef}
motionName={`${prefixCls}-${motionName}`}
getValueIndex={(val) =>
segmentedOptions.findIndex((n) => n.value === val)
}
onMotionStart={() => {
setThumbShow(true);
}}
onMotionEnd={() => {
setThumbShow(false);
}}
/>
))}
{segmentedOptions.map((segmentedOption) => (
<InternalSegmentedOption
key={segmentedOption.value}
prefixCls={prefixCls}
className={classNames(
segmentedOption.className,
`${prefixCls}-item`,
{
[`${prefixCls}-item-selected`]:
segmentedOption.value === rawValue && !thumbShow,
},
)}
checked={segmentedOption.value === rawValue}
onChange={handleChange}
{...segmentedOption}
disabled={!!disabled || !!segmentedOption.disabled}
/>
))}
</div>
</div>
);
},
Expand Down
Loading