Skip to content

Commit 53bfbfb

Browse files
committed
refactor(ui): add mixin to provide component's style in form
1 parent b69cf2d commit 53bfbfb

File tree

12 files changed

+50
-12
lines changed

12 files changed

+50
-12
lines changed

packages/ui/src/components/form/demos/3.IrregularLayout.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ export default function Demo() {
4141
>
4242
{({ username1, username2 }) => (
4343
<DCompose>
44-
<DInput dFormControl={username1} dPlaceholder="Username" />
45-
<DInput dFormControl={username2} dPlaceholder="Username" />
44+
<DInput style={{ width: '50%' }} dFormControl={username1} dPlaceholder="Username" />
45+
<DInput style={{ width: '50%' }} dFormControl={username2} dPlaceholder="Username" />
4646
</DCompose>
4747
)}
4848
</DForm.Item>

packages/ui/src/components/form/demos/5.ValidityResult.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ export default function Demo() {
6767
>
6868
{({ username3, username4 }) => (
6969
<DCompose>
70-
<DInput dFormControl={username3} dPlaceholder="error" />
71-
<DInput dFormControl={username4} dPlaceholder="required, minLength:warning,5" />
70+
<DInput style={{ width: '50%' }} dFormControl={username3} dPlaceholder="error" />
71+
<DInput style={{ width: '50%' }} dFormControl={username4} dPlaceholder="required, minLength:warning,5" />
7272
</DCompose>
7373
)}
7474
</DForm.Item>

packages/ui/src/components/input/Input.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ export function DInput(props: DInputProps): JSX.Element | null {
170170
<div
171171
{...restProps}
172172
className={getClassName(restProps.className, `${dPrefix}input`, {
173+
[`${dPrefix}input--number`]: dType === 'number',
173174
[`${dPrefix}input--${size}`]: size,
174175
[`${dPrefix}input--button-right`]: dType === 'number' && dNumbetButton && !disabled && !checkNodeExist(dSuffix),
175176
'is-disabled': disabled,

packages/ui/src/styles/components/cascader.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
@import 'mixins/form';
12
@import 'mixins/selectbox';
23

34
$cascader-option-height: 32px;
45

56
@include b(cascader) {
7+
@include component-in-form('#{&}') {
8+
width: 100%;
9+
}
10+
611
@include component-selectbox;
712

813
@include when(disabled) {

packages/ui/src/styles/components/compose.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
@import 'mixins/form';
12
@import 'mixins/size';
23

34
@include b(compose) {
5+
@include component-in-form('#{&}') {
6+
width: 100%;
7+
}
8+
49
$compose-support: "[data-compose-support='true']";
510
$compose-support--active: "[data-compose-support-active='true']";
611
$compose-support--disabled: "[data-compose-support-disabled='true']";

packages/ui/src/styles/components/date-picker.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
@use 'sass:map';
2+
@import 'mixins/form';
23
@import 'mixins/date-input';
34
@import 'mixins/overwrite';
45

56
@include b(date-picker) {
7+
@include component-in-form('#{&}') {
8+
max-width: 100%;
9+
}
10+
611
@include component-date-input;
712

813
@include e(popup) {

packages/ui/src/styles/components/form.scss

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,6 @@
110110
flex-wrap: wrap;
111111
align-items: center;
112112
min-height: var(--#{$rd-prefix}size);
113-
114-
.#{$rd-prefix}select,
115-
.#{$rd-prefix}cascader,
116-
.#{$rd-prefix}tree-select,
117-
.#{$rd-prefix}compose,
118-
.#{$rd-prefix}input:not(.#{$rd-prefix}input--number) {
119-
width: 100%;
120-
}
121113
}
122114

123115
@include e(pending) {

packages/ui/src/styles/components/input.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
@import 'mixins/form';
12
@import 'mixins/size';
23

34
@include b(input) {
5+
@include component-in-form('#{&}:not(#{&}--number)') {
6+
width: 100%;
7+
}
8+
@include component-in-form('#{&}--number') {
9+
max-width: 100%;
10+
}
11+
412
display: inline-flex;
513
align-items: center;
614
height: var(--#{$rd-prefix}size);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@mixin component-in-form($selector) {
2+
@at-root {
3+
.#{$rd-prefix}form__item-content > #{$selector} {
4+
@content;
5+
}
6+
}
7+
}

packages/ui/src/styles/components/select.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
@import 'mixins/form';
12
@import 'mixins/selectbox';
23

34
$select-option-height: 32px;
45

56
@include b(select) {
7+
@include component-in-form('#{&}') {
8+
width: 100%;
9+
}
10+
611
@include component-selectbox;
712

813
@include when(disabled) {

0 commit comments

Comments
 (0)