Browse Source

refactor: radio style

走鹃 3 years ago
parent
commit
0067bb02a5

+ 22 - 36
packages/semi-foundation/radio/radio.scss

@@ -6,9 +6,8 @@ $inner-width: $width-icon-medium;
 .#{$module} {
 .#{$module} {
     @include box-sizing;
     @include box-sizing;
     @include font-size-regular;
     @include font-size-regular;
-    position: relative;
     display: inline-flex;
     display: inline-flex;
-    flex-wrap: wrap;
+    column-gap: $spacing-radio_addon-paddingLeft;
 
 
     &.#{$module}-vertical {
     &.#{$module}-vertical {
         display: block;
         display: block;
@@ -78,6 +77,8 @@ $inner-width: $width-icon-medium;
     }
     }
 
 
     &-buttonRadioGroup {
     &-buttonRadioGroup {
+        // Button needs to be positioned relative to parent
+        position: relative;
         padding: $spacing-radio_buttonRadioGroup_middle-padding;
         padding: $spacing-radio_buttonRadioGroup_middle-padding;
         border-radius: $radius-radio_buttonRadio;
         border-radius: $radius-radio_buttonRadio;
         line-height: $font-radio_buttonRadioGroup_middle-lineHeight;
         line-height: $font-radio_buttonRadioGroup_middle-lineHeight;
@@ -106,7 +107,6 @@ $inner-width: $width-icon-medium;
         border: $width-radio_cardRadioGroup_checked-border solid transparent;
         border: $width-radio_cardRadioGroup_checked-border solid transparent;
 
 
         .#{$module}-inner {
         .#{$module}-inner {
-            position: relative;
             &-display {
             &-display {
                 background: $color-radio_card-bg-default;
                 background: $color-radio_card-bg-default;
             }
             }
@@ -205,19 +205,19 @@ $inner-width: $width-icon-medium;
     }
     }
 
 
     &-inner {
     &-inner {
-        position: absolute;
-        display: inline-block;
-        top: 2px;
-        left: 0;
+        display: inline-flex;
+        margin-top: 2px;
+        // WARN: The absolute positioning used by the input does not occupy space, and relative cannot be removed here.
+        position: relative;
         width: $width-radio_inner;
         width: $width-radio_inner;
         height: $width-radio_inner;
         height: $width-radio_inner;
         vertical-align: sub;
         vertical-align: sub;
         user-select: none; // prevent text under it will be selected when double click
         user-select: none; // prevent text under it will be selected when double click
 
 
         &-display {
         &-display {
-            position: absolute;
-            left: 0;
-            top: 0;
+            display: inline-flex;
+            align-items: center;
+            justify-content: center;
             @include box-sizing;
             @include box-sizing;
             width: $width-radio_inner;
             width: $width-radio_inner;
             height: $width-radio_inner;
             height: $width-radio_inner;
@@ -226,7 +226,6 @@ $inner-width: $width-icon-medium;
             background: $color-radio_default-bg-default;
             background: $color-radio_default-bg-default;
 
 
             .#{$prefix}-icon {
             .#{$prefix}-icon {
-                position: absolute;
                 width: 100%;
                 width: 100%;
                 height: 100%;
                 height: 100%;
                 font-size: 14px;
                 font-size: 14px;
@@ -234,6 +233,11 @@ $inner-width: $width-icon-medium;
         }
         }
     }
     }
 
 
+    &-content {
+        display: flex;
+        flex-direction: column;
+    }
+
     &:hover {
     &:hover {
         .#{$module}-inner-display {
         .#{$module}-inner-display {
             background: $color-radio_default-bg-hover;
             background: $color-radio_default-bg-hover;
@@ -248,8 +252,6 @@ $inner-width: $width-icon-medium;
 
 
     &-addon {
     &-addon {
         user-select: none;
         user-select: none;
-        padding-left: $spacing-radio_addon-paddingLeft;
-        margin-left: $spacing-radio_addon-marginLeft;
         color: $color-radio_default-text-default;
         color: $color-radio_default-text-default;
         display: inline-flex;
         display: inline-flex;
         align-items: center;
         align-items: center;
@@ -372,11 +374,7 @@ $inner-width: $width-icon-medium;
     }
     }
 
 
     &-extra {
     &-extra {
-        flex-grow: 1;
-        flex-basis: 100%;
-        flex-shrink: 0;
         color: $color-radio_extra-text-default;
         color: $color-radio_extra-text-default;
-        padding-left: $spacing-radio_extra-paddingLeft;
         box-sizing: border-box;
         box-sizing: border-box;
     }
     }
 
 
@@ -393,37 +391,25 @@ $inner-width: $width-icon-medium;
     @include font-size-regular;
     @include font-size-regular;
 
 
     &-vertical {
     &-vertical {
-        .#{$module} {
-            &:last-of-type {
-                margin-bottom: 0;
-            }
-        }
+        display: flex;
+        flex-direction: column;
+        row-gap: $spacing-radio_group_vertical-marginBottom;
+
         &-default {
         &-default {
             .#{$module} {
             .#{$module} {
-                display: block;
-                margin-bottom: $spacing-radio_group_vertical-marginBottom;
-
+                display: flex;
             }
             }
         }
         }
         &-card {
         &-card {
             .#{$module} {
             .#{$module} {
                 display: flex;
                 display: flex;
-                margin-bottom: $spacing-radio_card_group_vertical-marginBottom;
             }
             }
         }
         }
     }
     }
 
 
     &-horizontal {
     &-horizontal {
-        .#{$module} {
-            margin-right: $spacing-radio_group_horizontal-marginRight;
-
-            &:last-of-type {
-                margin-right: 0;
-            }
-        }
-        &-default {
-            display: inline-block;
-        }
+        display: inline-flex;
+        column-gap: $spacing-radio_group_horizontal-marginRight;
     }
     }
 
 
     &-buttonRadio {
     &-buttonRadio {

+ 0 - 47
packages/semi-foundation/radio/rtl.scss

@@ -18,61 +18,14 @@ $inner-width: $width-icon-medium;
             }
             }
         }
         }
 
 
-        &-inner {
-            left: auto;
-            right: 0;
-
-            &-display {
-                left: auto;
-                right: 0;
-            }
-        }
-
         &-addon {
         &-addon {
-            padding-left: 0;
-            margin-left: 0;
-            padding-right: $spacing-radio_addon-paddingLeft;
-            margin-right: $spacing-radio_addon-marginLeft;
-            
             &-buttonRadio {
             &-buttonRadio {
                 margin-right: $spacing-none;
                 margin-right: $spacing-none;
             }
             }
         }
         }
-
-        &-extra {
-            padding-left: 0;
-            padding-right: $spacing-radio_extra-paddingLeft;
-        }
-    }
-
-    &-isCardRadioGroup {
-        .#{$module}-inner {
-            margin-right: 0;
-            margin-left: $spacing-radio_cardRadioGroup_inner-marginRight;
-        }
-
-        .#{$module}-addon {
-            margin-right: 0;
-            padding-right: 0;
-        }
-
-        .#{$module}-extra {
-            padding-right: 0;
-        }
     }
     }
 
 
     .#{$module}Group {
     .#{$module}Group {
         direction: rtl;
         direction: rtl;
-
-        &-horizontal {
-            .#{$module} {
-                margin-right: 0;
-                margin-left: $spacing-radio_group_horizontal-marginRight;
-
-                &:last-of-type {
-                    margin-left: 0;
-                }
-            }
-        }
     }
     }
 }
 }

+ 5 - 5
packages/semi-ui/radio/_story/radio.stories.js

@@ -254,18 +254,18 @@ _RadioGroup.story = {
 
 
 export const RadioWithVertical = () => {
 export const RadioWithVertical = () => {
   return (
   return (
-    <Radio.Group>
-      <Radio value="A" displayMode="vertical">
+    <Radio.Group direction="vertical">
+      <Radio value="A">
         无限长的一串字The Storybook webapp UI can be customised with this addon. It can be used to
         无限长的一串字The Storybook webapp UI can be customised with this addon. It can be used to
         change the header, show/hide various UI elements and to enable full-screen mode by default.
         change the header, show/hide various UI elements and to enable full-screen mode by default.
       </Radio>
       </Radio>
-      <Radio value="C" displayMode="vertical">
+      <Radio value="C">
         C
         C
       </Radio>
       </Radio>
-      <Radio value="D" displayMode="vertical">
+      <Radio value="D">
         D
         D
       </Radio>
       </Radio>
-      <Radio value="E" displayMode="vertical">
+      <Radio value="E">
         E
         E
       </Radio>
       </Radio>
     </Radio.Group>
     </Radio.Group>

+ 3 - 5
packages/semi-ui/radio/radio.tsx

@@ -285,11 +285,9 @@ class Radio extends BaseComponent<RadioProps, RadioState> {
                     onInputFocus={this.handleFocusVisible}
                     onInputFocus={this.handleFocusVisible}
                     onInputBlur={this.handleBlur}
                     onInputBlur={this.handleBlur}
                 />
                 />
-                {
-                    isCardRadioGroup ?
-                        <div className={`${prefix}-isCardRadioGroup_content`}>{renderContent()}</div> :
-                        renderContent()
-                }
+                <div className={cls([`${prefix}-content`, { [`${prefix}-isCardRadioGroup_content`]: isCardRadioGroup }])}>
+                    {renderContent()}
+                </div>
             </label>
             </label>
         );
         );
     }
     }