@gm-pc/react 1.25.1-beta.1 → 1.26.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/common/hooks/index.ts +5 -5
- package/src/common/hooks/use_form/index.ts +2 -2
- package/src/common/hooks/use_form/use_form.ts +184 -184
- package/src/common/hooks/use_form/utils.ts +23 -23
- package/src/common/hooks/use_mutation_observer.ts +19 -19
- package/src/common/utils/date.ts +28 -28
- package/src/common/utils/get_record_partical_object.ts +4 -4
- package/src/common/utils/index.ts +3 -3
- package/src/common/utils/utils.ts +16 -16
- package/src/component/affix/affix.tsx +31 -31
- package/src/component/affix/index.ts +2 -2
- package/src/component/affix/stories.tsx +16 -16
- package/src/component/affix/style.less +3 -3
- package/src/component/auto_complete/auto_complete.tsx +202 -202
- package/src/component/auto_complete/index.ts +6 -6
- package/src/component/auto_complete/stories.tsx +37 -37
- package/src/component/auto_full/auto_full.tsx +36 -36
- package/src/component/auto_full/index.ts +1 -1
- package/src/component/box/box.tsx +29 -29
- package/src/component/box/box_form.tsx +83 -83
- package/src/component/box/box_pagination.tsx +12 -12
- package/src/component/box/box_panel.tsx +91 -91
- package/src/component/box/box_table.tsx +57 -57
- package/src/component/box/index.ts +10 -10
- package/src/component/box/stories.tsx +119 -119
- package/src/component/box/style.less +41 -41
- package/src/component/button/button.tsx +94 -94
- package/src/component/button/button_text.tsx +33 -33
- package/src/component/button/index.ts +4 -4
- package/src/component/button/stories.tsx +131 -131
- package/src/component/button/style.less +158 -158
- package/src/component/calendar/calendar.tsx +25 -25
- package/src/component/calendar/content.tsx +87 -87
- package/src/component/calendar/day.tsx +106 -106
- package/src/component/calendar/head.tsx +244 -244
- package/src/component/calendar/index.ts +4 -4
- package/src/component/calendar/range_calendar.tsx +121 -121
- package/src/component/calendar/stories.tsx +54 -54
- package/src/component/calendar/style.less +136 -136
- package/src/component/calendar/types.ts +56 -56
- package/src/component/calendar/week.tsx +27 -27
- package/src/component/card/card.tsx +148 -148
- package/src/component/card/form_card.tsx +42 -42
- package/src/component/card/index.ts +2 -2
- package/src/component/card/stories.tsx +90 -90
- package/src/component/card/style.less +125 -125
- package/src/component/checkbox/checkbox.tsx +75 -75
- package/src/component/checkbox/checkbox_group.tsx +51 -51
- package/src/component/checkbox/index.ts +5 -5
- package/src/component/checkbox/stories.tsx +152 -152
- package/src/component/checkbox/style.less +73 -73
- package/src/component/checkbox/util.ts +19 -19
- package/src/component/collapse/collapse.tsx +27 -27
- package/src/component/collapse/index.ts +2 -2
- package/src/component/collapse/stories.tsx +21 -21
- package/src/component/color_picker/color_list.ts +34 -34
- package/src/component/color_picker/color_picker.tsx +43 -43
- package/src/component/color_picker/color_select.tsx +97 -97
- package/src/component/color_picker/index.ts +2 -2
- package/src/component/color_picker/stories.tsx +20 -20
- package/src/component/color_picker/style.less +41 -41
- package/src/component/config_provider/config_provider.tsx +16 -16
- package/src/component/config_provider/context.ts +10 -10
- package/src/component/config_provider/index.ts +3 -3
- package/src/component/controlled_form/context.tsx +18 -18
- package/src/component/controlled_form/controlled_form.tsx +141 -141
- package/src/component/controlled_form/index.ts +8 -8
- package/src/component/controlled_form/items/index.tsx +115 -115
- package/src/component/controlled_form/items/utils.ts +132 -132
- package/src/component/controlled_form/stories/components/date_range_filter.tsx +83 -83
- package/src/component/controlled_form/stories/components/index.ts +2 -2
- package/src/component/controlled_form/stories/components/search_filter.tsx +52 -52
- package/src/component/controlled_form/stories/stories.tsx +372 -372
- package/src/component/date_picker/date_picker.tsx +187 -187
- package/src/component/date_picker/index.ts +2 -2
- package/src/component/date_picker/overlay.tsx +115 -115
- package/src/component/date_picker/stories.tsx +109 -109
- package/src/component/date_picker/style.less +23 -23
- package/src/component/date_picker/time_select.tsx +58 -58
- package/src/component/date_picker/types.ts +7 -7
- package/src/component/date_range_picker/date_range_picker.tsx +144 -144
- package/src/component/date_range_picker/index.ts +2 -2
- package/src/component/date_range_picker/left.tsx +107 -107
- package/src/component/date_range_picker/overlay.tsx +204 -204
- package/src/component/date_range_picker/stories.tsx +181 -181
- package/src/component/date_range_picker/style.less +41 -41
- package/src/component/date_range_picker/time_range_select.tsx +144 -144
- package/src/component/date_range_picker/two.tsx +108 -108
- package/src/component/date_range_picker/types.ts +42 -42
- package/src/component/date_range_picker/util.ts +11 -11
- package/src/component/dialog/alert.tsx +38 -38
- package/src/component/dialog/confirm.tsx +120 -120
- package/src/component/dialog/delete_com.tsx +27 -27
- package/src/component/dialog/dialog.tsx +70 -70
- package/src/component/dialog/index.ts +16 -16
- package/src/component/dialog/prompt.tsx +95 -95
- package/src/component/dialog/stories.tsx +195 -195
- package/src/component/dialog/types.ts +70 -70
- package/src/component/divider/divider.tsx +25 -25
- package/src/component/divider/index.ts +2 -2
- package/src/component/divider/stories.tsx +14 -14
- package/src/component/divider/style.less +29 -29
- package/src/component/flex/flex.tsx +133 -133
- package/src/component/flex/index.ts +2 -2
- package/src/component/flex/stories.tsx +17 -17
- package/src/component/flex/style.less +105 -105
- package/src/component/flip_number/flip_number.tsx +209 -209
- package/src/component/flip_number/index.ts +2 -2
- package/src/component/flip_number/stories.tsx +28 -28
- package/src/component/flip_number/utils.ts +58 -58
- package/src/component/form/context.tsx +15 -15
- package/src/component/form/form.tsx +142 -142
- package/src/component/form/form_block.tsx +39 -39
- package/src/component/form/form_button.tsx +28 -28
- package/src/component/form/form_group.tsx +157 -157
- package/src/component/form/form_item.tsx +141 -141
- package/src/component/form/form_panel.tsx +63 -63
- package/src/component/form/index.ts +15 -15
- package/src/component/form/stories.tsx +448 -448
- package/src/component/form/style.less +159 -159
- package/src/component/form/types.ts +110 -110
- package/src/component/function_set/function_set.tsx +84 -84
- package/src/component/function_set/index.ts +2 -2
- package/src/component/function_set/overlay.tsx +41 -41
- package/src/component/function_set/stories.tsx +71 -71
- package/src/component/function_set/types.ts +15 -15
- package/src/component/function_set/utils.ts +21 -21
- package/src/component/grid/col.tsx +55 -55
- package/src/component/grid/index.ts +3 -3
- package/src/component/grid/mixin.less +48 -48
- package/src/component/grid/row.tsx +27 -27
- package/src/component/grid/stories.tsx +65 -65
- package/src/component/grid/style.less +27 -27
- package/src/component/grid/types.ts +35 -35
- package/src/component/grid/util.ts +12 -12
- package/src/component/icon_down_up/icon_down_up.tsx +22 -22
- package/src/component/icon_down_up/index.ts +2 -2
- package/src/component/icon_down_up/stories.tsx +21 -21
- package/src/component/icon_down_up/style.less +10 -10
- package/src/component/icon_expand/icon_expand.tsx +22 -22
- package/src/component/icon_expand/index.ts +1 -1
- package/src/component/img_uploader/img_uploader.tsx +168 -168
- package/src/component/img_uploader/index.ts +2 -2
- package/src/component/img_uploader/stories.tsx +58 -58
- package/src/component/img_uploader/style.less +22 -22
- package/src/component/input/index.ts +5 -5
- package/src/component/input/input.tsx +24 -24
- package/src/component/input/input_close.tsx +51 -51
- package/src/component/input/stories.tsx +56 -56
- package/src/component/input/style.less +33 -33
- package/src/component/input_number/index.ts +2 -2
- package/src/component/input_number/input_number.tsx +115 -115
- package/src/component/input_number/stories.tsx +27 -27
- package/src/component/input_number/style.less +10 -10
- package/src/component/input_number/utils.ts +44 -44
- package/src/component/label/index.tsx +19 -19
- package/src/component/label/stories.tsx +26 -26
- package/src/component/label/style.less +34 -34
- package/src/component/layout_root/index.ts +2 -2
- package/src/component/layout_root/layout_root.tsx +116 -116
- package/src/component/layout_root/types.ts +38 -38
- package/src/component/level_list/index.ts +2 -2
- package/src/component/level_list/level_item.tsx +79 -79
- package/src/component/level_list/level_list.tsx +123 -123
- package/src/component/level_list/stories/constants.ts +72 -72
- package/src/component/level_list/stories/stories.tsx +87 -87
- package/src/component/level_list/style.less +41 -41
- package/src/component/level_list/types.ts +36 -36
- package/src/component/level_list/utils.ts +19 -19
- package/src/component/level_select/index.ts +7 -7
- package/src/component/level_select/level_select.tsx +216 -216
- package/src/component/level_select/multiple_level_select.tsx +104 -104
- package/src/component/level_select/stories.tsx +102 -102
- package/src/component/level_select/types.ts +38 -38
- package/src/component/level_select/util.ts +20 -20
- package/src/component/list/base.tsx +129 -129
- package/src/component/list/index.ts +3 -3
- package/src/component/list/list.tsx +61 -61
- package/src/component/list/stories.tsx +113 -113
- package/src/component/list/style.less +58 -58
- package/src/component/list/types.ts +37 -37
- package/src/component/loading/index.ts +10 -10
- package/src/component/loading/loading.tsx +26 -26
- package/src/component/loading/loading_chunk.tsx +37 -37
- package/src/component/loading/loading_full_screen.tsx +45 -45
- package/src/component/loading/stories.tsx +43 -43
- package/src/component/loading/style.less +69 -69
- package/src/component/loading/types.ts +30 -30
- package/src/component/mask/index.ts +2 -2
- package/src/component/mask/mask.tsx +22 -22
- package/src/component/mask/style.less +10 -10
- package/src/component/modal/clean_modal.tsx +14 -14
- package/src/component/modal/index.ts +5 -5
- package/src/component/modal/modal.tsx +145 -145
- package/src/component/modal/right_side_modal.tsx +22 -22
- package/src/component/modal/stories.tsx +132 -132
- package/src/component/modal/style.less +138 -138
- package/src/component/modal/types.ts +27 -27
- package/src/component/more_select/base.tsx +408 -408
- package/src/component/more_select/index.ts +6 -6
- package/src/component/more_select/more_select.tsx +137 -137
- package/src/component/more_select/render_list_filter.ts +39 -39
- package/src/component/more_select/stories.tsx +323 -323
- package/src/component/more_select/style.less +72 -72
- package/src/component/more_select/types.ts +114 -114
- package/src/component/multiple_selection/index.ts +2 -2
- package/src/component/multiple_selection/multiple_selection.tsx +118 -118
- package/src/component/multiple_selection/stories.tsx +37 -37
- package/src/component/multiple_selection/style.less +57 -57
- package/src/component/n_progress/index.ts +1 -1
- package/src/component/n_progress/n_progress.tsx +39 -39
- package/src/component/n_progress/stories.tsx +25 -25
- package/src/component/n_progress/style.less +39 -39
- package/src/component/nav/a.tsx +7 -7
- package/src/component/nav/index.ts +10 -10
- package/src/component/nav/nav.tsx +114 -114
- package/src/component/nav/nav_item.tsx +98 -98
- package/src/component/nav/nav_single_item.tsx +28 -28
- package/src/component/nav/popup.tsx +100 -100
- package/src/component/nav/portal.ts +17 -17
- package/src/component/nav/stories.tsx +152 -152
- package/src/component/nav/style.less +246 -246
- package/src/component/nav/types.ts +93 -93
- package/src/component/pagination/index.ts +2 -2
- package/src/component/pagination/left.tsx +52 -45
- package/src/component/pagination/page_with_count.tsx +115 -115
- package/src/component/pagination/page_without_count.tsx +64 -64
- package/src/component/pagination/pagination.tsx +23 -23
- package/src/component/pagination/right.tsx +79 -78
- package/src/component/pagination/stories.tsx +62 -62
- package/src/component/pagination/style.less +51 -51
- package/src/component/pagination/types.ts +16 -16
- package/src/component/pagination/util.ts +7 -7
- package/src/component/popover/index.ts +2 -2
- package/src/component/popover/popover.tsx +279 -279
- package/src/component/popover/stories.tsx +104 -104
- package/src/component/popover/types.ts +25 -25
- package/src/component/popover/utils.ts +22 -22
- package/src/component/popup/element_in_viewport.ts +33 -33
- package/src/component/popup/index.ts +4 -4
- package/src/component/popup/popup.tsx +149 -149
- package/src/component/popup/popup_content_confirm.tsx +106 -106
- package/src/component/popup/style.less +107 -107
- package/src/component/price/constant.ts +4 -4
- package/src/component/price/event_bus.ts +13 -13
- package/src/component/price/index.ts +2 -2
- package/src/component/price/price.tsx +154 -152
- package/src/component/price/stories.tsx +22 -22
- package/src/component/progress/index.ts +2 -2
- package/src/component/progress/progress.tsx +53 -53
- package/src/component/progress/stories.tsx +20 -20
- package/src/component/progress/style.less +35 -35
- package/src/component/progress_circle/index.ts +2 -2
- package/src/component/progress_circle/progress_circle.tsx +85 -85
- package/src/component/progress_circle/stories.tsx +31 -31
- package/src/component/progress_circle/style.less +21 -21
- package/src/component/radio/index.ts +5 -5
- package/src/component/radio/radio.tsx +72 -72
- package/src/component/radio/radio_group.tsx +48 -48
- package/src/component/radio/stories.tsx +103 -103
- package/src/component/radio/style.less +56 -56
- package/src/component/radio/util.ts +19 -19
- package/src/component/recommend_input/index.ts +2 -2
- package/src/component/recommend_input/recommend_input.tsx +100 -100
- package/src/component/recommend_input/stories.tsx +47 -47
- package/src/component/recommend_input/style.less +25 -25
- package/src/component/select/index.ts +2 -2
- package/src/component/select/select.tsx +172 -171
- package/src/component/select/stories.tsx +140 -140
- package/src/component/select/style.less +4 -4
- package/src/component/select/types.ts +29 -29
- package/src/component/selection/index.ts +2 -2
- package/src/component/selection/selection.tsx +162 -162
- package/src/component/selection/stories.tsx +45 -45
- package/src/component/selection/style.less +65 -65
- package/src/component/steps/index.ts +2 -2
- package/src/component/steps/steps.tsx +61 -61
- package/src/component/steps/stories.tsx +18 -18
- package/src/component/steps/style.less +39 -39
- package/src/component/storage/index.ts +1 -1
- package/src/component/storage/storage.ts +7 -7
- package/src/component/storage/stories.tsx +7 -7
- package/src/component/switch/index.ts +2 -2
- package/src/component/switch/stories.tsx +39 -39
- package/src/component/switch/style.less +60 -60
- package/src/component/switch/switch.tsx +127 -127
- package/src/component/table_select/index.ts +2 -2
- package/src/component/table_select/stories.tsx +97 -97
- package/src/component/table_select/style.less +20 -20
- package/src/component/table_select/table_select.tsx +92 -92
- package/src/component/table_select/types.ts +30 -30
- package/src/component/table_select/util.ts +15 -15
- package/src/component/tabs/index.ts +2 -2
- package/src/component/tabs/stories.tsx +172 -172
- package/src/component/tabs/style.less +149 -149
- package/src/component/tabs/tabs.tsx +232 -232
- package/src/component/textarea/index.ts +3 -3
- package/src/component/textarea/stories.tsx +37 -37
- package/src/component/textarea/style.less +12 -12
- package/src/component/textarea/textarea.tsx +22 -22
- package/src/component/time_span/index.ts +4 -4
- package/src/component/time_span/stories.tsx +87 -87
- package/src/component/time_span/style.less +45 -45
- package/src/component/time_span/time_span.tsx +129 -129
- package/src/component/time_span/time_span_picker.tsx +71 -71
- package/src/component/time_span/types.ts +58 -58
- package/src/component/time_span/util.ts +18 -18
- package/src/component/tip/index.ts +2 -2
- package/src/component/tip/stories.tsx +44 -44
- package/src/component/tip/style.less +53 -53
- package/src/component/tip/tip.tsx +95 -95
- package/src/component/tip/types.ts +20 -20
- package/src/component/tooltip/index.ts +2 -2
- package/src/component/tooltip/stories.tsx +32 -32
- package/src/component/tooltip/tooltip.tsx +40 -40
- package/src/component/transfer/index.ts +2 -2
- package/src/component/transfer/stories.tsx +140 -140
- package/src/component/transfer/transfer.tsx +147 -147
- package/src/component/transfer/types.ts +42 -42
- package/src/component/tree/bottom.tsx +34 -34
- package/src/component/tree/find.tsx +73 -73
- package/src/component/tree/index.ts +2 -2
- package/src/component/tree/item.tsx +75 -75
- package/src/component/tree/list.tsx +123 -123
- package/src/component/tree/search.tsx +29 -29
- package/src/component/tree/stories.tsx +309 -309
- package/src/component/tree/style.less +35 -35
- package/src/component/tree/tree.tsx +238 -238
- package/src/component/tree/types.ts +155 -155
- package/src/component/tree/util.ts +208 -208
- package/src/component/uploader/default_container.tsx +24 -24
- package/src/component/uploader/default_image.tsx +15 -15
- package/src/component/uploader/index.ts +10 -10
- package/src/component/uploader/stories.tsx +53 -53
- package/src/component/uploader/style.less +22 -22
- package/src/component/uploader/types.ts +25 -25
- package/src/component/uploader/uploader.tsx +62 -62
- package/src/component/v_browser/context/browser.ts +7 -7
- package/src/component/v_browser/context/browserWindow.ts +7 -7
- package/src/component/v_browser/hooks/useWindowEffect.ts +53 -53
- package/src/component/v_browser/index.ts +4 -4
- package/src/component/v_browser/types.ts +46 -46
- package/src/component/v_browser/ui/iframe_portal.tsx +28 -28
- package/src/component/v_browser/ui/index.tsx +213 -213
- package/src/component/v_browser/ui/style.less +113 -113
- package/src/component/v_browser/ui/window_wrapper.tsx +74 -74
- package/src/component/v_browser/v_browser.stories.mdx +128 -128
- package/src/component/v_browser/v_browser.tsx +287 -287
- package/src/css/base.less +64 -64
- package/src/css/bg.less +52 -52
- package/src/css/border.less +40 -40
- package/src/css/cursor.less +19 -19
- package/src/css/display.less +16 -16
- package/src/css/distance.less +93 -93
- package/src/css/error.less +8 -8
- package/src/css/other.less +15 -15
- package/src/css/overflow.less +23 -23
- package/src/css/position.less +11 -11
- package/src/css/svg.less +48 -48
- package/src/css/text.less +127 -127
- package/src/css/var/mixin.less +75 -75
- package/src/css/var/variables.less +125 -125
- package/src/event_type.ts +11 -11
- package/src/index.less +64 -64
- package/src/index.ts +61 -61
- package/src/svg/calendar-month.svg +8 -8
- package/src/svg/calendar-year.svg +13 -13
- package/src/svg/calendar.svg +17 -17
- package/src/svg/check-detail.svg +18 -18
- package/src/svg/close-circle.svg +13 -13
- package/src/svg/close-square.svg +12 -12
- package/src/svg/closeup.svg +20 -20
- package/src/svg/delete.svg +10 -10
- package/src/svg/down-small.svg +1 -1
- package/src/svg/down.svg +1 -1
- package/src/svg/edit-box.svg +17 -17
- package/src/svg/edit-pen.svg +17 -17
- package/src/svg/empty.svg +27 -27
- package/src/svg/expand.svg +21 -21
- package/src/svg/left-small.svg +1 -1
- package/src/svg/more.svg +10 -10
- package/src/svg/next.svg +40 -40
- package/src/svg/pen.svg +12 -12
- package/src/svg/remove.svg +1 -1
- package/src/svg/right-small.svg +1 -1
- package/src/svg/search.svg +8 -8
- package/src/svg/setting.svg +17 -17
- package/src/svg/up-small.svg +1 -1
- package/src/svg/up.svg +1 -1
- package/src/svg/vbrowser-tab-delete.svg +8 -8
- package/src/svg/vbrowser-tab-left.svg +8 -8
- package/src/svg/vbrowser-tab-right.svg +8 -8
- package/src/types.ts +33 -33
- package/src/validator/index.ts +16 -16
- package/src/validator/rules.ts +61 -61
- package/src/validator/types.ts +10 -10
- package/src/validator/validator.ts +95 -95
- package/src/var.less +2 -2
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import FlipNumber from './flip_number'
|
|
3
|
-
import { observable } from 'mobx'
|
|
4
|
-
|
|
5
|
-
const store = observable({
|
|
6
|
-
from: 0,
|
|
7
|
-
to: 0,
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
setTimeout(() => {
|
|
11
|
-
store.from = 234.2343
|
|
12
|
-
store.to = 709394
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
export const ComFlipNumber = () => (
|
|
16
|
-
<FlipNumber
|
|
17
|
-
useGroup
|
|
18
|
-
delay={1000}
|
|
19
|
-
decimal={2}
|
|
20
|
-
from={store.from}
|
|
21
|
-
to={store.to}
|
|
22
|
-
className='gm-text-20'
|
|
23
|
-
/>
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
export default {
|
|
27
|
-
title: '反馈/FlipNumber',
|
|
28
|
-
}
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import FlipNumber from './flip_number'
|
|
3
|
+
import { observable } from 'mobx'
|
|
4
|
+
|
|
5
|
+
const store = observable({
|
|
6
|
+
from: 0,
|
|
7
|
+
to: 0,
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
setTimeout(() => {
|
|
11
|
+
store.from = 234.2343
|
|
12
|
+
store.to = 709394
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
export const ComFlipNumber = () => (
|
|
16
|
+
<FlipNumber
|
|
17
|
+
useGroup
|
|
18
|
+
delay={1000}
|
|
19
|
+
decimal={2}
|
|
20
|
+
from={store.from}
|
|
21
|
+
to={store.to}
|
|
22
|
+
className='gm-text-20'
|
|
23
|
+
/>
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
export default {
|
|
27
|
+
title: '反馈/FlipNumber',
|
|
28
|
+
}
|
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
import _ from 'lodash'
|
|
2
|
-
import Big from 'big.js'
|
|
3
|
-
import { is } from '@gm-common/tool'
|
|
4
|
-
|
|
5
|
-
function formatNum(number: number, decimals: number, useGrouping: boolean) {
|
|
6
|
-
const num = Big(number).toFixed(decimals)
|
|
7
|
-
return useGrouping
|
|
8
|
-
? num.toString().replace(/^\d+/g, (m) => m.replace(/(?=(?!^)(\d{3})+$)/g, ','))
|
|
9
|
-
: num
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function getNumLength(str1: string, str2: string): number {
|
|
13
|
-
return Math.max(str1.length, str2.length)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function filterForNum(strArr: any[]): number[] {
|
|
17
|
-
return _.filter(strArr, (item) => is.number(item)) as number[]
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
interface GetRawArray {
|
|
21
|
-
(numStr: string, length: number): GetRawArrayReturns
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
interface GetRawArrayReturns {
|
|
25
|
-
rawList: string[]
|
|
26
|
-
symbolList: { symbol: string; position: number }[]
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @description 根据字符串返回相应的反转字符串数组以及符号数组
|
|
31
|
-
* @param numStr 需要转换成数组的数字字符串
|
|
32
|
-
* @param length 需要转换的长度
|
|
33
|
-
*/
|
|
34
|
-
const getRawArray: GetRawArray = function (numStr, length) {
|
|
35
|
-
const alignNum = (str: string, len: number): string => {
|
|
36
|
-
return str.length < len ? alignNum(`0${str}`, len) : str
|
|
37
|
-
}
|
|
38
|
-
const symbolList: { symbol: string; position: number }[] = []
|
|
39
|
-
const rawStrArr = alignNum(numStr, length).split('')
|
|
40
|
-
_.forEach(rawStrArr, (item, index) => {
|
|
41
|
-
if (item === ',' || item === '.') {
|
|
42
|
-
symbolList.push({
|
|
43
|
-
symbol: item,
|
|
44
|
-
position: index,
|
|
45
|
-
})
|
|
46
|
-
}
|
|
47
|
-
})
|
|
48
|
-
const rawList = filterForNum(rawStrArr)
|
|
49
|
-
.map((item) => `${item}`)
|
|
50
|
-
.reverse()
|
|
51
|
-
_.forEach(symbolList, (item) => {
|
|
52
|
-
rawList.splice(item.position, 0, item.symbol)
|
|
53
|
-
})
|
|
54
|
-
return { rawList, symbolList }
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export { formatNum, filterForNum, getNumLength, getRawArray }
|
|
58
|
-
export type { GetRawArray, GetRawArrayReturns }
|
|
1
|
+
import _ from 'lodash'
|
|
2
|
+
import Big from 'big.js'
|
|
3
|
+
import { is } from '@gm-common/tool'
|
|
4
|
+
|
|
5
|
+
function formatNum(number: number, decimals: number, useGrouping: boolean) {
|
|
6
|
+
const num = Big(number).toFixed(decimals)
|
|
7
|
+
return useGrouping
|
|
8
|
+
? num.toString().replace(/^\d+/g, (m) => m.replace(/(?=(?!^)(\d{3})+$)/g, ','))
|
|
9
|
+
: num
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function getNumLength(str1: string, str2: string): number {
|
|
13
|
+
return Math.max(str1.length, str2.length)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function filterForNum(strArr: any[]): number[] {
|
|
17
|
+
return _.filter(strArr, (item) => is.number(item)) as number[]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface GetRawArray {
|
|
21
|
+
(numStr: string, length: number): GetRawArrayReturns
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface GetRawArrayReturns {
|
|
25
|
+
rawList: string[]
|
|
26
|
+
symbolList: { symbol: string; position: number }[]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @description 根据字符串返回相应的反转字符串数组以及符号数组
|
|
31
|
+
* @param numStr 需要转换成数组的数字字符串
|
|
32
|
+
* @param length 需要转换的长度
|
|
33
|
+
*/
|
|
34
|
+
const getRawArray: GetRawArray = function (numStr, length) {
|
|
35
|
+
const alignNum = (str: string, len: number): string => {
|
|
36
|
+
return str.length < len ? alignNum(`0${str}`, len) : str
|
|
37
|
+
}
|
|
38
|
+
const symbolList: { symbol: string; position: number }[] = []
|
|
39
|
+
const rawStrArr = alignNum(numStr, length).split('')
|
|
40
|
+
_.forEach(rawStrArr, (item, index) => {
|
|
41
|
+
if (item === ',' || item === '.') {
|
|
42
|
+
symbolList.push({
|
|
43
|
+
symbol: item,
|
|
44
|
+
position: index,
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
const rawList = filterForNum(rawStrArr)
|
|
49
|
+
.map((item) => `${item}`)
|
|
50
|
+
.reverse()
|
|
51
|
+
_.forEach(symbolList, (item) => {
|
|
52
|
+
rawList.splice(item.position, 0, item.symbol)
|
|
53
|
+
})
|
|
54
|
+
return { rawList, symbolList }
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { formatNum, filterForNum, getNumLength, getRawArray }
|
|
58
|
+
export type { GetRawArray, GetRawArrayReturns }
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { createContext } from 'react'
|
|
2
|
-
import { FormBtnPosition } from './types'
|
|
3
|
-
|
|
4
|
-
export interface FormContextOptions {
|
|
5
|
-
labelWidth?: string
|
|
6
|
-
disabledCol?: boolean
|
|
7
|
-
inline?: boolean
|
|
8
|
-
btnPosition?: FormBtnPosition
|
|
9
|
-
colWidth?: string
|
|
10
|
-
canValidate?: boolean
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const FormContext = createContext<Readonly<FormContextOptions>>({})
|
|
14
|
-
|
|
15
|
-
export default FormContext
|
|
1
|
+
import { createContext } from 'react'
|
|
2
|
+
import { FormBtnPosition } from './types'
|
|
3
|
+
|
|
4
|
+
export interface FormContextOptions {
|
|
5
|
+
labelWidth?: string
|
|
6
|
+
disabledCol?: boolean
|
|
7
|
+
inline?: boolean
|
|
8
|
+
btnPosition?: FormBtnPosition
|
|
9
|
+
colWidth?: string
|
|
10
|
+
canValidate?: boolean
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const FormContext = createContext<Readonly<FormContextOptions>>({})
|
|
14
|
+
|
|
15
|
+
export default FormContext
|
|
@@ -1,142 +1,142 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
Component,
|
|
3
|
-
FormEvent,
|
|
4
|
-
PropsWithChildren,
|
|
5
|
-
ReactElement,
|
|
6
|
-
ReactNode,
|
|
7
|
-
ComponentType,
|
|
8
|
-
Children,
|
|
9
|
-
} from 'react'
|
|
10
|
-
import classNames from 'classnames'
|
|
11
|
-
import FormContext from './context'
|
|
12
|
-
import Validator from '../../validator'
|
|
13
|
-
import { FormProps, FormItemProps } from './types'
|
|
14
|
-
import { ConfigConsumer } from '../config_provider'
|
|
15
|
-
const { Provider } = FormContext
|
|
16
|
-
|
|
17
|
-
interface FormState {
|
|
18
|
-
canValidate: boolean
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* 请使用ControledForm
|
|
22
|
-
* @deprecated
|
|
23
|
-
*/
|
|
24
|
-
class Form extends Component<FormProps, FormState> {
|
|
25
|
-
static defaultProps = {
|
|
26
|
-
btnPosition: 'center',
|
|
27
|
-
colWidth: '320px',
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
readonly state: FormState = {
|
|
31
|
-
canValidate: false,
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public apiDoValidate = (): boolean => {
|
|
35
|
-
const error = this._validateAll()
|
|
36
|
-
this.setState({ canValidate: error })
|
|
37
|
-
return !error
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
private _getFormItemFields = (
|
|
41
|
-
children: ReactElement,
|
|
42
|
-
formItems: ReactElement<FormItemProps>[]
|
|
43
|
-
) => {
|
|
44
|
-
Children.toArray(children).forEach((value: ReactNode) => {
|
|
45
|
-
const child = value as ReactElement<PropsWithChildren<FormItemProps>, ComponentType>
|
|
46
|
-
if (
|
|
47
|
-
child.type &&
|
|
48
|
-
['FormItem', 'ControlledFormItem'].includes(child.type.displayName!)
|
|
49
|
-
) {
|
|
50
|
-
formItems.push(child)
|
|
51
|
-
} else if (child.props && child.props.children) {
|
|
52
|
-
this._getFormItemFields(child.props.children as ReactElement, formItems)
|
|
53
|
-
}
|
|
54
|
-
})
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
private _validateAll = (): boolean => {
|
|
58
|
-
const { children } = this.props
|
|
59
|
-
const helpList: { label: ReactNode; help: string }[] = []
|
|
60
|
-
const formItems: ReactElement<FormItemProps>[] = []
|
|
61
|
-
this._getFormItemFields(children as ReactElement, formItems)
|
|
62
|
-
formItems.forEach((item) => {
|
|
63
|
-
if (item.props.error) {
|
|
64
|
-
helpList.push({
|
|
65
|
-
label: item.props.label,
|
|
66
|
-
help: item.props.help!,
|
|
67
|
-
})
|
|
68
|
-
} else if (item.props.validate) {
|
|
69
|
-
let help = ''
|
|
70
|
-
if (item.props.required) {
|
|
71
|
-
help = item.props.validate(function (value: any) {
|
|
72
|
-
return Validator.validate(Validator.TYPE.required, value)
|
|
73
|
-
})
|
|
74
|
-
} else {
|
|
75
|
-
help = item.props.validate()
|
|
76
|
-
}
|
|
77
|
-
if (help) {
|
|
78
|
-
helpList.push({
|
|
79
|
-
label: item.props.label,
|
|
80
|
-
help,
|
|
81
|
-
})
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
})
|
|
85
|
-
return !!helpList.length
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
private _handleSubmit = (event: FormEvent<HTMLFormElement>): void => {
|
|
89
|
-
event.preventDefault()
|
|
90
|
-
const { onSubmit, onSubmitValidated } = this.props
|
|
91
|
-
onSubmit && onSubmit(event)
|
|
92
|
-
|
|
93
|
-
const error = this._validateAll()
|
|
94
|
-
if (!error) {
|
|
95
|
-
onSubmitValidated && onSubmitValidated()
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
this.setState({
|
|
99
|
-
canValidate: error,
|
|
100
|
-
})
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
render() {
|
|
104
|
-
const {
|
|
105
|
-
inline,
|
|
106
|
-
labelWidth,
|
|
107
|
-
disabledCol,
|
|
108
|
-
className,
|
|
109
|
-
children,
|
|
110
|
-
hasButtonInGroup,
|
|
111
|
-
onSubmitValidated,
|
|
112
|
-
btnPosition,
|
|
113
|
-
colWidth,
|
|
114
|
-
...rest
|
|
115
|
-
} = this.props
|
|
116
|
-
const { canValidate } = this.state
|
|
117
|
-
return (
|
|
118
|
-
<Provider
|
|
119
|
-
value={{ labelWidth, disabledCol, inline, btnPosition, colWidth, canValidate }}
|
|
120
|
-
>
|
|
121
|
-
<ConfigConsumer>
|
|
122
|
-
{({ fontSize }) => (
|
|
123
|
-
<form
|
|
124
|
-
{...rest}
|
|
125
|
-
className={classNames(
|
|
126
|
-
'gm-form',
|
|
127
|
-
{ 'form-inline': inline, [`gm-form-text-${fontSize}`]: fontSize },
|
|
128
|
-
className
|
|
129
|
-
)}
|
|
130
|
-
onSubmit={this._handleSubmit}
|
|
131
|
-
>
|
|
132
|
-
{children}
|
|
133
|
-
{hasButtonInGroup && <button type='submit' style={{ display: 'none' }} />}
|
|
134
|
-
</form>
|
|
135
|
-
)}
|
|
136
|
-
</ConfigConsumer>
|
|
137
|
-
</Provider>
|
|
138
|
-
)
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export default Form
|
|
1
|
+
import React, {
|
|
2
|
+
Component,
|
|
3
|
+
FormEvent,
|
|
4
|
+
PropsWithChildren,
|
|
5
|
+
ReactElement,
|
|
6
|
+
ReactNode,
|
|
7
|
+
ComponentType,
|
|
8
|
+
Children,
|
|
9
|
+
} from 'react'
|
|
10
|
+
import classNames from 'classnames'
|
|
11
|
+
import FormContext from './context'
|
|
12
|
+
import Validator from '../../validator'
|
|
13
|
+
import { FormProps, FormItemProps } from './types'
|
|
14
|
+
import { ConfigConsumer } from '../config_provider'
|
|
15
|
+
const { Provider } = FormContext
|
|
16
|
+
|
|
17
|
+
interface FormState {
|
|
18
|
+
canValidate: boolean
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 请使用ControledForm
|
|
22
|
+
* @deprecated
|
|
23
|
+
*/
|
|
24
|
+
class Form extends Component<FormProps, FormState> {
|
|
25
|
+
static defaultProps = {
|
|
26
|
+
btnPosition: 'center',
|
|
27
|
+
colWidth: '320px',
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
readonly state: FormState = {
|
|
31
|
+
canValidate: false,
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public apiDoValidate = (): boolean => {
|
|
35
|
+
const error = this._validateAll()
|
|
36
|
+
this.setState({ canValidate: error })
|
|
37
|
+
return !error
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private _getFormItemFields = (
|
|
41
|
+
children: ReactElement,
|
|
42
|
+
formItems: ReactElement<FormItemProps>[]
|
|
43
|
+
) => {
|
|
44
|
+
Children.toArray(children).forEach((value: ReactNode) => {
|
|
45
|
+
const child = value as ReactElement<PropsWithChildren<FormItemProps>, ComponentType>
|
|
46
|
+
if (
|
|
47
|
+
child.type &&
|
|
48
|
+
['FormItem', 'ControlledFormItem'].includes(child.type.displayName!)
|
|
49
|
+
) {
|
|
50
|
+
formItems.push(child)
|
|
51
|
+
} else if (child.props && child.props.children) {
|
|
52
|
+
this._getFormItemFields(child.props.children as ReactElement, formItems)
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private _validateAll = (): boolean => {
|
|
58
|
+
const { children } = this.props
|
|
59
|
+
const helpList: { label: ReactNode; help: string }[] = []
|
|
60
|
+
const formItems: ReactElement<FormItemProps>[] = []
|
|
61
|
+
this._getFormItemFields(children as ReactElement, formItems)
|
|
62
|
+
formItems.forEach((item) => {
|
|
63
|
+
if (item.props.error) {
|
|
64
|
+
helpList.push({
|
|
65
|
+
label: item.props.label,
|
|
66
|
+
help: item.props.help!,
|
|
67
|
+
})
|
|
68
|
+
} else if (item.props.validate) {
|
|
69
|
+
let help = ''
|
|
70
|
+
if (item.props.required) {
|
|
71
|
+
help = item.props.validate(function (value: any) {
|
|
72
|
+
return Validator.validate(Validator.TYPE.required, value)
|
|
73
|
+
})
|
|
74
|
+
} else {
|
|
75
|
+
help = item.props.validate()
|
|
76
|
+
}
|
|
77
|
+
if (help) {
|
|
78
|
+
helpList.push({
|
|
79
|
+
label: item.props.label,
|
|
80
|
+
help,
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
return !!helpList.length
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private _handleSubmit = (event: FormEvent<HTMLFormElement>): void => {
|
|
89
|
+
event.preventDefault()
|
|
90
|
+
const { onSubmit, onSubmitValidated } = this.props
|
|
91
|
+
onSubmit && onSubmit(event)
|
|
92
|
+
|
|
93
|
+
const error = this._validateAll()
|
|
94
|
+
if (!error) {
|
|
95
|
+
onSubmitValidated && onSubmitValidated()
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
this.setState({
|
|
99
|
+
canValidate: error,
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
render() {
|
|
104
|
+
const {
|
|
105
|
+
inline,
|
|
106
|
+
labelWidth,
|
|
107
|
+
disabledCol,
|
|
108
|
+
className,
|
|
109
|
+
children,
|
|
110
|
+
hasButtonInGroup,
|
|
111
|
+
onSubmitValidated,
|
|
112
|
+
btnPosition,
|
|
113
|
+
colWidth,
|
|
114
|
+
...rest
|
|
115
|
+
} = this.props
|
|
116
|
+
const { canValidate } = this.state
|
|
117
|
+
return (
|
|
118
|
+
<Provider
|
|
119
|
+
value={{ labelWidth, disabledCol, inline, btnPosition, colWidth, canValidate }}
|
|
120
|
+
>
|
|
121
|
+
<ConfigConsumer>
|
|
122
|
+
{({ fontSize }) => (
|
|
123
|
+
<form
|
|
124
|
+
{...rest}
|
|
125
|
+
className={classNames(
|
|
126
|
+
'gm-form',
|
|
127
|
+
{ 'form-inline': inline, [`gm-form-text-${fontSize}`]: fontSize },
|
|
128
|
+
className
|
|
129
|
+
)}
|
|
130
|
+
onSubmit={this._handleSubmit}
|
|
131
|
+
>
|
|
132
|
+
{children}
|
|
133
|
+
{hasButtonInGroup && <button type='submit' style={{ display: 'none' }} />}
|
|
134
|
+
</form>
|
|
135
|
+
)}
|
|
136
|
+
</ConfigConsumer>
|
|
137
|
+
</Provider>
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export default Form
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import React, { Children, CSSProperties, FC, useContext } from 'react'
|
|
2
|
-
import classNames from 'classnames'
|
|
3
|
-
import FormContext from './context'
|
|
4
|
-
import { Flex } from '../flex'
|
|
5
|
-
import { FormBlockProps } from './types'
|
|
6
|
-
|
|
7
|
-
const FormBlock: FC<FormBlockProps> = ({
|
|
8
|
-
col = 1,
|
|
9
|
-
disabledCol,
|
|
10
|
-
inline,
|
|
11
|
-
className,
|
|
12
|
-
style,
|
|
13
|
-
children,
|
|
14
|
-
}) => {
|
|
15
|
-
const context = useContext(FormContext)
|
|
16
|
-
disabledCol = disabledCol ?? context.disabledCol
|
|
17
|
-
inline = inline ?? context.inline
|
|
18
|
-
const { colWidth } = context
|
|
19
|
-
const _cw = +colWidth!.replace('px', '')
|
|
20
|
-
const _style: CSSProperties = Object.assign(
|
|
21
|
-
{},
|
|
22
|
-
style,
|
|
23
|
-
disabledCol || inline ? {} : { width: _cw * col }
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
return (
|
|
27
|
-
<Flex wrap style={_style} className={classNames('gm-form-block', className)}>
|
|
28
|
-
{Children.map(children, (child, index) => (
|
|
29
|
-
<Flex key={index} column>
|
|
30
|
-
{child}
|
|
31
|
-
</Flex>
|
|
32
|
-
))}
|
|
33
|
-
</Flex>
|
|
34
|
-
)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
FormBlock.displayName = 'FormBlock'
|
|
38
|
-
|
|
39
|
-
export default FormBlock
|
|
1
|
+
import React, { Children, CSSProperties, FC, useContext } from 'react'
|
|
2
|
+
import classNames from 'classnames'
|
|
3
|
+
import FormContext from './context'
|
|
4
|
+
import { Flex } from '../flex'
|
|
5
|
+
import { FormBlockProps } from './types'
|
|
6
|
+
|
|
7
|
+
const FormBlock: FC<FormBlockProps> = ({
|
|
8
|
+
col = 1,
|
|
9
|
+
disabledCol,
|
|
10
|
+
inline,
|
|
11
|
+
className,
|
|
12
|
+
style,
|
|
13
|
+
children,
|
|
14
|
+
}) => {
|
|
15
|
+
const context = useContext(FormContext)
|
|
16
|
+
disabledCol = disabledCol ?? context.disabledCol
|
|
17
|
+
inline = inline ?? context.inline
|
|
18
|
+
const { colWidth } = context
|
|
19
|
+
const _cw = +colWidth!.replace('px', '')
|
|
20
|
+
const _style: CSSProperties = Object.assign(
|
|
21
|
+
{},
|
|
22
|
+
style,
|
|
23
|
+
disabledCol || inline ? {} : { width: _cw * col }
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<Flex wrap style={_style} className={classNames('gm-form-block', className)}>
|
|
28
|
+
{Children.map(children, (child, index) => (
|
|
29
|
+
<Flex key={index} column>
|
|
30
|
+
{child}
|
|
31
|
+
</Flex>
|
|
32
|
+
))}
|
|
33
|
+
</Flex>
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
FormBlock.displayName = 'FormBlock'
|
|
38
|
+
|
|
39
|
+
export default FormBlock
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import React, { CSSProperties, FC, useContext } from 'react'
|
|
2
|
-
import { FormButtonProps } from './types'
|
|
3
|
-
import FormContext from './context'
|
|
4
|
-
import { Flex } from '../flex'
|
|
5
|
-
|
|
6
|
-
const FormButton: FC<FormButtonProps> = ({ labelWidth, btnPosition, children }) => {
|
|
7
|
-
const context = useContext(FormContext)
|
|
8
|
-
labelWidth = labelWidth ?? context.labelWidth
|
|
9
|
-
btnPosition = btnPosition ?? context.btnPosition
|
|
10
|
-
const { inline } = context
|
|
11
|
-
const style: CSSProperties = {
|
|
12
|
-
marginLeft: btnPosition === 'left' && !inline && labelWidth ? labelWidth : 0,
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return (
|
|
16
|
-
<Flex
|
|
17
|
-
column
|
|
18
|
-
alignStart={btnPosition === 'left'}
|
|
19
|
-
alignCenter={btnPosition === 'center'}
|
|
20
|
-
alignEnd={btnPosition === 'right'}
|
|
21
|
-
style={style}
|
|
22
|
-
>
|
|
23
|
-
<div>{children}</div>
|
|
24
|
-
</Flex>
|
|
25
|
-
)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export default FormButton
|
|
1
|
+
import React, { CSSProperties, FC, useContext } from 'react'
|
|
2
|
+
import { FormButtonProps } from './types'
|
|
3
|
+
import FormContext from './context'
|
|
4
|
+
import { Flex } from '../flex'
|
|
5
|
+
|
|
6
|
+
const FormButton: FC<FormButtonProps> = ({ labelWidth, btnPosition, children }) => {
|
|
7
|
+
const context = useContext(FormContext)
|
|
8
|
+
labelWidth = labelWidth ?? context.labelWidth
|
|
9
|
+
btnPosition = btnPosition ?? context.btnPosition
|
|
10
|
+
const { inline } = context
|
|
11
|
+
const style: CSSProperties = {
|
|
12
|
+
marginLeft: btnPosition === 'left' && !inline && labelWidth ? labelWidth : 0,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<Flex
|
|
17
|
+
column
|
|
18
|
+
alignStart={btnPosition === 'left'}
|
|
19
|
+
alignCenter={btnPosition === 'center'}
|
|
20
|
+
alignEnd={btnPosition === 'right'}
|
|
21
|
+
style={style}
|
|
22
|
+
>
|
|
23
|
+
<div>{children}</div>
|
|
24
|
+
</Flex>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default FormButton
|