amotify 0.0.3 → 0.0.4

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.
Files changed (185) hide show
  1. package/dist/src/@jsminAmotifyExtension/_.d.ts +4 -0
  2. package/dist/src/@jsminAmotifyExtension/fetch.d.ts +9 -0
  3. package/dist/src/@jsminAmotifyExtension/formCollect.d.ts +1 -0
  4. package/dist/src/@jsminAmotifyExtension/spreadSheet.d.ts +4 -0
  5. package/dist/src/@jsminAmotifyExtension/variables.d.ts +0 -0
  6. package/dist/src/@types/_.d.ts +6 -0
  7. package/dist/src/@types/amot.d.ts +260 -0
  8. package/dist/src/@types/fn.d.ts +1040 -0
  9. package/dist/src/@types/index.d.ts +62 -0
  10. package/dist/src/@types/jsminAmotifyExtension.d.ts +134 -0
  11. package/dist/src/@types/module.d.ts +2 -0
  12. package/dist/src/@types/state.d.ts +145 -0
  13. package/dist/src/Atoms/@export.d.ts +4 -0
  14. package/dist/src/Atoms/FAIcon/parts.d.ts +2 -0
  15. package/dist/src/Atoms/Logo/parts.d.ts +1 -0
  16. package/dist/src/Atoms/Various/parts.d.ts +9 -0
  17. package/dist/src/Functions/@export.d.ts +12 -0
  18. package/dist/src/Functions/Button/_.d.ts +1 -0
  19. package/dist/src/Functions/Cropper/parts.d.ts +1 -0
  20. package/dist/src/Functions/Effects/Fade.d.ts +1 -0
  21. package/dist/src/Functions/Effects/Ripple.d.ts +1 -0
  22. package/dist/src/Functions/Effects/_.d.ts +3 -0
  23. package/dist/src/Functions/Input/Chips/Selector.d.ts +1 -0
  24. package/dist/src/Functions/Input/Chips/_.d.ts +2 -0
  25. package/dist/src/Functions/Input/DigitCharacters.d.ts +1 -0
  26. package/dist/src/Functions/Input/File/_.d.ts +2 -0
  27. package/dist/src/Functions/Input/Hidden.d.ts +1 -0
  28. package/dist/src/Functions/Input/List/_.d.ts +1 -0
  29. package/dist/src/Functions/Input/Segmented/_.d.ts +1 -0
  30. package/dist/src/Functions/Input/Select/_.d.ts +1 -0
  31. package/dist/src/Functions/Input/Slider/_.d.ts +1 -0
  32. package/dist/src/Functions/Input/Switch/_.d.ts +1 -0
  33. package/dist/src/Functions/Input/Text.d.ts +5 -0
  34. package/dist/src/Functions/Input/TextArea.d.ts +1 -0
  35. package/dist/src/Functions/Input/Time/Picker.d.ts +1 -0
  36. package/dist/src/Functions/Input/Time/_.d.ts +2 -0
  37. package/dist/src/Functions/Input/_.d.ts +5 -0
  38. package/dist/src/Functions/Input/core.d.ts +34 -0
  39. package/dist/src/Functions/Inputs/_.d.ts +3 -0
  40. package/dist/src/Functions/Inputs/text.d.ts +12 -0
  41. package/dist/src/Functions/Layout/PageNotFound.d.ts +1 -0
  42. package/dist/src/Functions/Layout/PageRouter.d.ts +2 -0
  43. package/dist/src/Functions/Layout/PageViewController/parts.d.ts +1 -0
  44. package/dist/src/Functions/Layout/Plate.d.ts +1 -0
  45. package/dist/src/Functions/Layout/RootViewController/parts.d.ts +1 -0
  46. package/dist/src/Functions/Layout/SwipeView/parts.d.ts +2 -0
  47. package/dist/src/Functions/Layout/TabBar.d.ts +1 -0
  48. package/dist/src/Functions/Layout/_.d.ts +2 -0
  49. package/dist/src/Functions/Loader/corner.d.ts +1 -0
  50. package/dist/src/Functions/Loader/mini.d.ts +33 -0
  51. package/dist/src/Functions/Loader/parts.d.ts +3 -0
  52. package/dist/src/Functions/Loader/top.d.ts +1 -0
  53. package/dist/src/Functions/Sheet/parts.d.ts +2 -0
  54. package/dist/src/Functions/SnackBar/parts.d.ts +2 -0
  55. package/dist/src/Functions/Table/Data/parts.d.ts +3 -0
  56. package/dist/src/Functions/Table/Drag/parts.d.ts +1 -0
  57. package/dist/src/Functions/Table/Normal/parts.d.ts +1 -0
  58. package/dist/src/Functions/Table/_.d.ts +9 -0
  59. package/dist/src/Functions/Tooltips/parts.d.ts +2 -0
  60. package/dist/src/Global/@export.d.ts +12 -0
  61. package/dist/src/Global/LaunchReactApplication.d.ts +1 -0
  62. package/dist/src/Global/styleConverter.d.ts +2 -0
  63. package/dist/src/Molecules/@export.d.ts +21 -0
  64. package/dist/src/Molecules/Accordion/parts.d.ts +2 -0
  65. package/dist/src/Molecules/LinkifyText/parts.d.ts +1 -0
  66. package/dist/src/Molecules/List.d.ts +1 -0
  67. package/dist/src/Organisms/@export.d.ts +2 -0
  68. package/dist/src/Organisms/DisplayStyleInput/_.d.ts +1 -0
  69. package/dist/src/Organisms/DisplayStyleInput/darkmode.d.ts +1 -0
  70. package/dist/src/Organisms/DisplayStyleInput/themeColor.d.ts +27 -0
  71. package/dist/src/Templates/@export.d.ts +2 -0
  72. package/dist/src/Templates/PlayGround/parts.d.ts +1 -0
  73. package/dist/src/config.d.ts +16 -0
  74. package/dist/src/launch.d.ts +9 -0
  75. package/dist/src/preload.d.ts +1 -0
  76. package/package.json +2 -2
  77. package/src/@jsminAmotifyExtension/_.tsx +4 -0
  78. package/src/@jsminAmotifyExtension/fetch.tsx +107 -0
  79. package/src/@jsminAmotifyExtension/formCollect.tsx +89 -0
  80. package/src/@jsminAmotifyExtension/spreadSheet.tsx +159 -0
  81. package/src/@jsminAmotifyExtension/variables.tsx +130 -0
  82. package/src/@styles/@app.scss +4 -0
  83. package/src/@styles/@variables/customProps.scss +109 -0
  84. package/src/@styles/@variables/styleSet.scss +38 -0
  85. package/src/@styles/@variables/themeColor.scss +71 -0
  86. package/src/@styles/@variables/var.scss +171 -0
  87. package/src/@styles/UniStyling.scss +996 -0
  88. package/src/@styles/init.scss +154 -0
  89. package/src/@types/_.tsx +6 -0
  90. package/src/@types/amot.tsx +323 -0
  91. package/src/@types/fn.tsx +1210 -0
  92. package/src/@types/index.tsx +74 -0
  93. package/src/@types/jsminAmotifyExtension.tsx +143 -0
  94. package/src/@types/module.tsx +2 -0
  95. package/src/@types/state.tsx +199 -0
  96. package/src/Atoms/@export.tsx +32 -0
  97. package/src/Atoms/FAIcon/parts.tsx +117 -0
  98. package/src/Atoms/FAIcon/style.module.scss +9 -0
  99. package/src/Atoms/Logo/parts.tsx +335 -0
  100. package/src/Atoms/Logo/style.module.scss +96 -0
  101. package/src/Atoms/Various/parts.tsx +157 -0
  102. package/src/Atoms/Various/style.module.scss +40 -0
  103. package/src/Functions/@export.tsx +29 -0
  104. package/src/Functions/Button/_.tsx +305 -0
  105. package/src/Functions/Button/style.module.scss +183 -0
  106. package/src/Functions/Cropper/parts.tsx +1061 -0
  107. package/src/Functions/Cropper/style.module.scss +62 -0
  108. package/src/Functions/Effects/Fade.tsx +81 -0
  109. package/src/Functions/Effects/Ripple.tsx +141 -0
  110. package/src/Functions/Effects/_.tsx +33 -0
  111. package/src/Functions/Effects/style.module.scss +83 -0
  112. package/src/Functions/Input/Chips/Selector.tsx +451 -0
  113. package/src/Functions/Input/Chips/_.tsx +286 -0
  114. package/src/Functions/Input/Chips/style.module.scss +6 -0
  115. package/src/Functions/Input/DigitCharacters.tsx +241 -0
  116. package/src/Functions/Input/File/_.tsx +596 -0
  117. package/src/Functions/Input/File/style.module.scss +34 -0
  118. package/src/Functions/Input/Hidden.tsx +18 -0
  119. package/src/Functions/Input/List/_.tsx +383 -0
  120. package/src/Functions/Input/List/style.module.scss +84 -0
  121. package/src/Functions/Input/Segmented/_.tsx +238 -0
  122. package/src/Functions/Input/Segmented/style.module.scss +81 -0
  123. package/src/Functions/Input/Select/_.tsx +225 -0
  124. package/src/Functions/Input/Select/style.module.scss +10 -0
  125. package/src/Functions/Input/Slider/_.tsx +519 -0
  126. package/src/Functions/Input/Slider/style.module.scss +67 -0
  127. package/src/Functions/Input/Switch/_.tsx +177 -0
  128. package/src/Functions/Input/Switch/style.module.scss +18 -0
  129. package/src/Functions/Input/Text.tsx +437 -0
  130. package/src/Functions/Input/TextArea.tsx +115 -0
  131. package/src/Functions/Input/Time/Picker.tsx +950 -0
  132. package/src/Functions/Input/Time/_.tsx +736 -0
  133. package/src/Functions/Input/Time/style.module.scss +72 -0
  134. package/src/Functions/Input/_.tsx +793 -0
  135. package/src/Functions/Input/core.tsx +461 -0
  136. package/src/Functions/Input/style.module.scss +43 -0
  137. package/src/Functions/Inputs/_.tsx +5 -0
  138. package/src/Functions/Inputs/style.module.scss +15 -0
  139. package/src/Functions/Inputs/text.tsx +67 -0
  140. package/src/Functions/Inputs/types.d.ts +1 -0
  141. package/src/Functions/Layout/PageNotFound.tsx +81 -0
  142. package/src/Functions/Layout/PageRouter.tsx +107 -0
  143. package/src/Functions/Layout/PageViewController/parts.tsx +32 -0
  144. package/src/Functions/Layout/Plate.tsx +30 -0
  145. package/src/Functions/Layout/RootViewController/parts.tsx +290 -0
  146. package/src/Functions/Layout/RootViewController/style.module.scss +24 -0
  147. package/src/Functions/Layout/SwipeView/parts.tsx +380 -0
  148. package/src/Functions/Layout/SwipeView/style.module.scss +19 -0
  149. package/src/Functions/Layout/TabBar.tsx +64 -0
  150. package/src/Functions/Layout/_.tsx +20 -0
  151. package/src/Functions/Loader/corner.tsx +78 -0
  152. package/src/Functions/Loader/mini.tsx +117 -0
  153. package/src/Functions/Loader/parts.tsx +105 -0
  154. package/src/Functions/Loader/style.module.scss +222 -0
  155. package/src/Functions/Loader/top.tsx +90 -0
  156. package/src/Functions/Sheet/parts.tsx +972 -0
  157. package/src/Functions/Sheet/style.module.scss +235 -0
  158. package/src/Functions/SnackBar/parts.tsx +215 -0
  159. package/src/Functions/SnackBar/style.module.scss +25 -0
  160. package/src/Functions/Table/Data/parts.tsx +955 -0
  161. package/src/Functions/Table/Drag/parts.tsx +448 -0
  162. package/src/Functions/Table/Normal/parts.tsx +123 -0
  163. package/src/Functions/Table/_.tsx +170 -0
  164. package/src/Functions/Table/style.module.scss +92 -0
  165. package/src/Functions/Tooltips/parts.tsx +52 -0
  166. package/src/Global/@export.tsx +138 -0
  167. package/src/Global/LaunchReactApplication.tsx +30 -0
  168. package/src/Global/exe.tsx +0 -0
  169. package/src/Global/styleConverter.tsx +435 -0
  170. package/src/Molecules/@export.tsx +95 -0
  171. package/src/Molecules/Accordion/parts.tsx +146 -0
  172. package/src/Molecules/Accordion/style.module.scss +13 -0
  173. package/src/Molecules/LinkifyText/parts.tsx +54 -0
  174. package/src/Molecules/List.tsx +30 -0
  175. package/src/Organisms/@export.tsx +5 -0
  176. package/src/Organisms/DisplayStyleInput/_.tsx +18 -0
  177. package/src/Organisms/DisplayStyleInput/darkmode.tsx +112 -0
  178. package/src/Organisms/DisplayStyleInput/themeColor.tsx +210 -0
  179. package/src/Templates/@export.tsx +7 -0
  180. package/src/Templates/PlayGround/parts.tsx +115 -0
  181. package/src/Templates/PlayGround/style.module.scss +38 -0
  182. package/src/config.tsx +132 -0
  183. package/src/launch.tsx +100 -0
  184. package/src/preload.tsx +49 -0
  185. package/tsconfig.json +27 -14
@@ -0,0 +1,177 @@
1
+ import {
2
+ React
3
+ } from '@global';
4
+ import {
5
+ Box,
6
+ FAIcon
7
+ } from '@atoms';
8
+ import {
9
+ Row
10
+ } from '@mols';
11
+ import {
12
+ Buttons
13
+ } from '@functions';
14
+ import {
15
+ BoxWrapper,
16
+ SubmitForm,
17
+ ValidationCheck,
18
+ CommonEffects
19
+ } from '../core';
20
+ import style from './style.module.scss';
21
+
22
+ const {
23
+ useState
24
+ } = React;
25
+
26
+ function DefaultValidation( props: {
27
+ value: any
28
+ params: any
29
+ } ): amotify.fn.Input.Validation.Result {
30
+ let { value,params } = props;
31
+ let { required } = params as amotify.fn.Input.TextArea.PlainParams;
32
+ let notice: amotify.fn.Input.Validation.NoticeTypes[] = [];
33
+
34
+ if ( required && !value ) {
35
+ notice.push( { type: 'invalid',label: 'ONになっていません' } );
36
+ }
37
+
38
+ return {
39
+ ok: !notice.filter( ( { type } ) => type == 'invalid' ).length,
40
+ notice: notice
41
+ }
42
+ }
43
+
44
+ export const SwitchInput: FNC<amotify.fn.Input.Switch.PlainParams> = ( params ) => {
45
+ let {
46
+ componentID,
47
+ color = 'posi',
48
+ required,
49
+ form,
50
+ id,
51
+
52
+ enableFormSubmit,
53
+
54
+ checkValidationAtFirst,
55
+ onChange,onKeyDown,
56
+ onValidate,
57
+ onUpdateValue,onUpdateValidValue,
58
+ value = '',
59
+ icon = '',
60
+ appearance = 'material',
61
+
62
+ ...others
63
+ } = params;
64
+
65
+ let Default_Status: amotify.fn.Input.Status.Plain = {
66
+ componentID: params.componentID || '',
67
+ dataValue: value,
68
+ eventType: 'init',
69
+ eventID: $.uuidGen()
70
+ }
71
+ let [ val_status,set_status ] = useState( Default_Status );
72
+ let [ val_validate,set_validate ] = useState( {
73
+ ok: false,
74
+ notice: []
75
+ } as amotify.fn.Input.Validation.Result );
76
+ let isChecked = !!val_status.dataValue;
77
+
78
+ CommonEffects( {
79
+ params,
80
+ val_status,
81
+ set_status,
82
+ val_validate,
83
+ set_validate,
84
+ DefaultValidation,
85
+ onUpdateValue,onUpdateValidValue,
86
+ ExtraOverrideParams: {
87
+ dataValue: value,
88
+ formatValue: value
89
+ },
90
+ } );
91
+
92
+ return ( <BoxWrapper
93
+ val_status={ val_status }
94
+ set_status={ set_status }
95
+ val_validate={ val_validate }
96
+ params={ params }
97
+ >
98
+ <input
99
+ type='checkbox'
100
+ data-form={ form }
101
+ data-input-type={ 'switch' }
102
+ data-validation={ val_validate.ok }
103
+ data-component-id={ val_status.componentID }
104
+ data-value={ val_status.dataValue }
105
+ checked={ val_status.dataValue }
106
+ className={ style.Input }
107
+ id={ id }
108
+ onKeyDown={ ( event ) => {
109
+ if ( onKeyDown ) onKeyDown( event );
110
+ if ( enableFormSubmit ) SubmitForm( event );
111
+ } }
112
+ onChange={ ( event ) => {
113
+ if ( val_validate.ok ) set_validate( { ok: false,notice: [] } );
114
+ set_status( {
115
+ ...val_status,
116
+ dataValue: event.target.checked,
117
+ eventType: 'update',
118
+ eventID: $.uuidGen(),
119
+ } );
120
+
121
+ if ( onChange ) onChange( event );
122
+ } }
123
+ { ...others }
124
+ />
125
+ <Buttons.Label.Plain
126
+ tabIndex={ -1 }
127
+ htmlFor={ id }
128
+ padding={ '1/3' }
129
+ transition='middle'
130
+ borderRadius={ '1.tone.primary' }
131
+ className={ style.Label }
132
+ >
133
+ <Box
134
+ { ...appearance == 'applely' ? {
135
+ padding: '1/4',
136
+ isRounded: true,
137
+ backgroundColor: isChecked ? color : '5.layer.darker'
138
+ } : {} }
139
+ >
140
+ <Row.Center
141
+ unitHeight={ 2.5 }
142
+ position='relative'
143
+ freeCSS={ {
144
+ width: 12 * 4.5
145
+ } }
146
+ >
147
+ { appearance == 'material' ? <Box
148
+ position='absolute'
149
+ backgroundColor={ isChecked ? color : '5.layer.darker' }
150
+ borderRadius={ 'sphere' }
151
+ unitHeight={ 1 }
152
+ transition='middle'
153
+ width={ 1 }
154
+ className={ style.Bar }
155
+ opacity='middle'
156
+ /> : null }
157
+ <Box
158
+ position='absolute'
159
+ top={ 0 }
160
+ left={ 0 }
161
+ backgroundColor={ appearance == 'material' && isChecked ? color : 'white' }
162
+ transition='middle'
163
+ ssSphere={ 2.5 }
164
+ boxShadow={ 2 }
165
+ className={ style.Dot }
166
+ >
167
+ { icon ? <FAIcon
168
+ transition='middle'
169
+ fontColor={ appearance == 'applely' && isChecked ? color : 'white' }
170
+ d={ icon }
171
+ /> : null }
172
+ </Box>
173
+ </Row.Center>
174
+ </Box>
175
+ </Buttons.Label.Plain>
176
+ </BoxWrapper> );
177
+ }
@@ -0,0 +1,18 @@
1
+ @use '@uniVar' as *;
2
+ .Input {
3
+ position: absolute;
4
+ height: 0;
5
+ width: 0;
6
+ overflow: hidden;
7
+ &:checked + .Label {
8
+ .Dot {
9
+ left: calc(100% - $unit2-5 ) !important;
10
+ }
11
+ }
12
+ &:focus + .Label {
13
+ box-shadow: 0 0 0 $unit1_3 $color-layer3;
14
+ }
15
+ &[disabled] + .Label {
16
+ opacity: .4;
17
+ }
18
+ }
@@ -0,0 +1,437 @@
1
+ import {
2
+ React,
3
+ } from '@global';
4
+ const {
5
+ useEffect,
6
+ useState,
7
+ } = React;
8
+
9
+ import {
10
+ Box,
11
+ } from '@atoms';
12
+
13
+ import {
14
+ BoxWrapper,
15
+ SubmitForm,
16
+ CommonEffects
17
+ } from './core';
18
+
19
+ import style from './style.module.scss';
20
+
21
+ const ValidateTypes: {
22
+ [ key: string ]: {
23
+ reg: RegExp
24
+ exist: boolean
25
+ reason: ReactElement
26
+ }
27
+ } = {
28
+ number: {
29
+ reg: /^-?[0-9\.]+$/g,exist: true,
30
+ reason: '半角数字で入力してください'
31
+ },
32
+ digitNumber: {
33
+ reg: /^-?[0-9\.]+$/g,exist: true,
34
+ reason: '半角数字で入力してください'
35
+ },
36
+ fileName: {
37
+ reg: /[¥\/;:*\?\"\'\|\.\s\n\r\<\>]/g,exist: false,
38
+ reason: '空白または一部の特殊文字は使用できません'
39
+ },
40
+ creditCard: {
41
+ reg: /^\d{16}$/g,exist: true,
42
+ reason: '16桁の数字で入力してください'
43
+ },
44
+ email: {
45
+ reg: /^[A-Za-z0-9]{1}[A-Za-z0-9_.-]*@{1}[A-Za-z0-9_.-]+\.[A-Za-z0-9]+$/,exist: true,
46
+ reason: <>
47
+ <Box>○○○○@○○○○.○○○の形式で入力してください</Box>
48
+ <Box>最後の文字に.(ドット)を入れることはできません</Box>
49
+ </>,
50
+ },
51
+ password: {
52
+ reg: /^(?=[^A-Z]*[A-Z])(?=[^a-z]*[a-z])(?=[^0-9]*[0-9]).{8,}$/,exist: true,
53
+ reason: '8文字以上、半角英数大小文字で入力してください'
54
+ },
55
+ tel: {
56
+ reg: /^(0|\(?\+\d{1,3}\)?\s)[-0-9]{9,12}$/g,exist: true,
57
+ reason: <>
58
+ <Box>0から始まる番号のみ入力可能です</Box>
59
+ <Box>9~12桁の数字で入力してください</Box>
60
+ <Box>数字のみ入力可能です</Box>
61
+ </>
62
+ },
63
+ url: {
64
+ reg: /^https?:\/\/[^\n\s]+(\.|\:)[^\n\s\.\:]+$/,exist: true,
65
+ reason: 'URL形式 : http(s)://◯◯◯◯'
66
+ },
67
+ postal: {
68
+ reg: /^\d{7}$/g,exist: true,
69
+ reason: '7桁の数字で入力してください'
70
+ }
71
+ }
72
+
73
+ const DataLeveling = ( params: {
74
+ min?: number | null
75
+ max?: number | null
76
+ restrict: amotify.fn.Input.Text.RestrictTypes,
77
+ value: any
78
+ } ) => {
79
+ let {
80
+ restrict,
81
+ value = ''
82
+ } = params;
83
+
84
+ let dataValue = String( value );
85
+ let minus = false;
86
+ if ( [ 'tel','number','digitNumber','test','postal','creditCard' ].includes( restrict ) ) {
87
+ dataValue = dataValue.zen2hanNumber();
88
+ }
89
+ if ( [ 'postal','creditCard' ].includes( restrict ) ) {
90
+ dataValue = dataValue.removeLetters();
91
+ }
92
+ if ( [ 'number','digitNumber' ].includes( restrict ) ) {
93
+ if ( dataValue ) {
94
+ if ( dataValue == '-' ) {
95
+
96
+ } else if ( dataValue == '0-' ) {
97
+ dataValue = '-';
98
+ } else {
99
+ if ( dataValue[ 0 ] == '-' ) minus = true;
100
+ dataValue = dataValue.replace( /[^0-9\.]/ig,'' );
101
+
102
+ let Amount = Number( dataValue );
103
+ if ( Amount === 0 ) minus = false;
104
+ if ( minus ) Amount = -1 * Amount;
105
+
106
+ if ( $.is.exist( params.min ) ) {
107
+ Amount = Math.max( Amount,Number( params.min ) );
108
+ }
109
+ if ( $.is.exist( params.max ) ) {
110
+ Amount = Math.min( Amount,Number( params.max ) );
111
+ }
112
+ dataValue = String( Math.abs( Amount ) );
113
+ }
114
+ }
115
+ }
116
+
117
+ let formatValue = dataValue;
118
+ if ( restrict == 'digitNumber' ) {
119
+ if ( dataValue && dataValue != '-' ) {
120
+ let arrary = [];
121
+ for ( let index = dataValue.length - 1; index >= 0; index-- ) {
122
+ arrary.unshift( dataValue[ index ] );
123
+ let Index = ( dataValue.length - 1 ) - index + 1;
124
+ if (
125
+ index != 0 && Index % 3 == 0 ) {
126
+ arrary.unshift( ',' );
127
+ }
128
+ }
129
+ formatValue = arrary.join( '' );
130
+ }
131
+ } else if ( restrict == 'postal' ) {
132
+ if ( dataValue.length >= 4 ) {
133
+ formatValue = dataValue.clip( 0,3 ) + '-' + dataValue.clip( 3 );
134
+ }
135
+ } else if ( restrict == 'creditCard' ) {
136
+ formatValue = dataValue.replace( /.{4}(?=.)/g,"$& " );
137
+ }
138
+
139
+ if ( [ 'number','digitNumber' ].includes( restrict ) ) {
140
+ if ( minus ) {
141
+ dataValue = '-' + dataValue;
142
+ formatValue = '-' + formatValue;
143
+ }
144
+ }
145
+
146
+ return {
147
+ formatValue,
148
+ dataValue
149
+ };
150
+ }
151
+
152
+ const setSelection: {
153
+ ( props: {
154
+ id?: string,
155
+ restrict: amotify.fn.Input.Text.RestrictTypes
156
+ val_status: any
157
+ } ): void
158
+ } = ( props ) => {
159
+ let {
160
+ id,
161
+ restrict,
162
+ val_status
163
+ } = props;
164
+
165
+ let input = $( '#' + id )[ 0 ] as HTMLInputElement;
166
+ if ( input ) {
167
+ if ( val_status.prevValue && val_status.formatValue ) {
168
+ let {
169
+ formatValue: currentValue,
170
+ prevValue,
171
+ caretFrom,caretTo
172
+ } = val_status;
173
+
174
+ if ( restrict == 'creditCard' ) {
175
+ if ( currentValue.length >= prevValue.length ) {
176
+ if ( caretFrom % 5 == 0 ) {
177
+ caretFrom++; caretTo++;
178
+ }
179
+ }
180
+ input.setSelectionRange( caretFrom,caretTo );
181
+ } else if ( restrict == 'postal' ) {
182
+ if ( currentValue.length == 5 && prevValue.length == 3 ) {
183
+ caretFrom++; caretTo++;
184
+ }
185
+ input.setSelectionRange( caretFrom,caretTo );
186
+ } else if ( restrict == 'digitNumber' ) {
187
+ let margin = currentValue.length - prevValue.length;
188
+
189
+ if ( margin == 2 ) {
190
+ caretFrom++; caretTo++;
191
+ }
192
+ if ( margin == -2 ) {
193
+ caretFrom--; caretTo--;
194
+ }
195
+ input.setSelectionRange( caretFrom,caretTo );
196
+ }
197
+ }
198
+ }
199
+ }
200
+ export const TextValidate = ( value: any,restrict: amotify.fn.Input.Text.RestrictTypes ) => {
201
+ let response = {
202
+ ok: true,
203
+ body: '' as any
204
+ };
205
+ ( () => {
206
+ let kit = ValidateTypes[ restrict ];
207
+ if ( !kit ) return;
208
+
209
+ let reason = kit.reason;
210
+ if ( kit ) {
211
+ let valid = Boolean( Number( !!value.match( kit.reg ) ) ^ Number( !kit.exist ) );
212
+ response = {
213
+ ok: valid,
214
+ body: valid ? '' : reason
215
+ }
216
+ }
217
+ } )();
218
+ return response;
219
+ }
220
+
221
+ function DefaultValidation( props: {
222
+ value: any
223
+ params: any
224
+ } ): amotify.fn.Input.Validation.Result {
225
+ let {
226
+ value,
227
+ params
228
+ } = props;
229
+ let {
230
+ restrict = 'text',
231
+ maxLength = 255,
232
+ required
233
+ } = params as amotify.fn.Input.Text.OriginParams
234
+ let notice: amotify.fn.Input.Validation.NoticeTypes[] = [];
235
+
236
+ if ( $.is.exist( maxLength ) ) {
237
+ if ( value.length >= Number( maxLength ) ) {
238
+ notice.push( { type: 'invalid',label: maxLength + '字以内で入力してください' } );
239
+ }
240
+ }
241
+ if ( value ) {
242
+ let Valid = TextValidate( value,restrict );
243
+ if ( !Valid.ok ) notice.push( { type: 'invalid',label: Valid.body } );
244
+ } else if ( required ) {
245
+ notice.push( { type: 'invalid',label: '必須項目です' } );
246
+ }
247
+
248
+ return {
249
+ ok: !notice.filter( ( { type } ) => type == 'invalid' ).length,
250
+ notice: notice
251
+ }
252
+ }
253
+
254
+ export const TextInput: FNC<amotify.fn.Input.Text.OriginParams> = ( params ) => {
255
+ let {
256
+ componentID,
257
+ tone,
258
+ required,
259
+ restrict = 'text',
260
+ form,
261
+ autoComplete = 'off',
262
+ autoCapitalize = 'off',
263
+
264
+ enableFormSubmit,
265
+ clearButton = false,
266
+
267
+ checkValidationAtFirst,
268
+ onChange,onKeyDown,
269
+ onValidate,
270
+ onUpdateValue,
271
+ onUpdateValidValue,
272
+ value = '',
273
+ leftIndicator,rightIndicator,rightIcon,
274
+ maxLength,
275
+ min,
276
+ max,
277
+
278
+ ...others
279
+ } = params;
280
+
281
+ let inputType = restrict == 'password' ? 'password' : 'text';
282
+ let inputMode: 'numeric' | 'text' | 'email' = [ 'number','digitNumber','tel','creditCard' ].includes( restrict ) ? 'numeric' : restrict == 'email' ? 'email' : 'text';
283
+
284
+ let Default_Status: amotify.fn.Input.Status.Text = {
285
+ componentID: componentID!,
286
+ ...DataLeveling( {
287
+ min,max,
288
+ restrict,
289
+ value
290
+ } ),
291
+ prevValue: '',
292
+ eventType: 'init',
293
+ eventID: $.uuidGen(),
294
+ caretFrom: null as any,
295
+ caretTo: null as any
296
+ }
297
+ let [ val_status,set_status ] = useState( Default_Status );
298
+ let [ val_validate,set_validate ] = useState( {
299
+ ok: false,
300
+ notice: []
301
+ } as amotify.fn.Input.Validation.Result );
302
+
303
+ CommonEffects( {
304
+ params,
305
+ val_status,
306
+ set_status,
307
+ val_validate,
308
+ set_validate,
309
+ DefaultValidation,
310
+ onUpdateValue,
311
+ onUpdateValidValue,
312
+ ExtraOverrideParams: {
313
+ ...DataLeveling( {
314
+ min,max,
315
+ restrict,
316
+ value
317
+ } )
318
+ }
319
+ } );
320
+
321
+ useEffect( () => {
322
+ setSelection( { id: params.id,restrict,val_status } );
323
+ },[ val_status ] );
324
+
325
+ return (
326
+ <BoxWrapper
327
+ val_status={ val_status }
328
+ set_status={ set_status }
329
+ val_validate={ val_validate }
330
+ params={ params }
331
+ >
332
+ <input
333
+ type={ inputType }
334
+ inputMode={ inputMode }
335
+ data-form={ form }
336
+ data-input-type={ 'text' }
337
+ data-validation={ val_validate.ok }
338
+ data-value={ val_status.dataValue }
339
+ data-component-id={ val_status.componentID }
340
+ value={ val_status.formatValue }
341
+ autoComplete={ autoComplete }
342
+ autoCapitalize={ autoCapitalize }
343
+ onKeyDown={ ( event ) => {
344
+ let { key,target } = event;
345
+ {
346
+ let input = target as HTMLInputElement;
347
+ let { selectionStart,selectionEnd } = input;
348
+ let caretFrom = Number( selectionStart );
349
+ let caretTo = Number( selectionEnd )
350
+
351
+ let _v = val_status.formatValue[ Number( caretFrom ) ];
352
+ let v_ = val_status.formatValue[ Number( caretFrom ) - 1 ];
353
+ if ( key == 'Delete' && (
354
+ ( restrict == 'creditCard' && _v == ' ' ) ||
355
+ ( restrict == 'postal' && _v == '-' ) ||
356
+ ( restrict == 'digitNumber' && _v == ',' )
357
+ ) ) {
358
+ input.setSelectionRange( caretFrom + 1,caretTo + 1 );
359
+ event.preventDefault();
360
+ }
361
+ if ( key == 'Backspace' && (
362
+ ( restrict == 'creditCard' && v_ == ' ' ) ||
363
+ ( restrict == 'postal' && v_ == '-' ) ||
364
+ ( restrict == 'digitNumber' && v_ == ',' )
365
+ ) ) {
366
+ input.setSelectionRange( caretFrom - 1,caretTo - 1 );
367
+ event.preventDefault();
368
+ }
369
+ }
370
+
371
+ if ( [ 'number','digitNumber','creditCard' ].includes( restrict ) ) {
372
+ if ( key == 'Clear' ) {
373
+ set_status( {
374
+ ...val_status,
375
+ dataValue: '',
376
+ formatValue: '',
377
+ eventType: 'update',
378
+ eventID: $.uuidGen(),
379
+ } )
380
+ }
381
+ }
382
+ if ( [ 'number','digitNumber' ].includes( restrict ) ) {
383
+ if ( [ 'ArrowUp','ArrowDown' ].includes( key ) ) {
384
+ let direction = Number( key == 'ArrowUp' ) * 2 - 1;
385
+ let Value = String( Number( val_status.dataValue ) + direction );
386
+ if ( val_validate.ok ) {
387
+ set_validate( { ok: false,notice: [] } );
388
+ }
389
+ set_status( {
390
+ ...val_status,
391
+ ...DataLeveling( {
392
+ min,max,
393
+ restrict,
394
+ value: Value
395
+ } ),
396
+ eventType: 'update',
397
+ eventID: $.uuidGen(),
398
+ } );
399
+ event.preventDefault();
400
+ }
401
+ }
402
+
403
+ if ( onKeyDown ) onKeyDown( event );
404
+ if ( enableFormSubmit ) SubmitForm( event );
405
+ } }
406
+ onChange={ ( event ) => {
407
+ let {
408
+ value: rawValue,
409
+ selectionStart,
410
+ selectionEnd
411
+ } = event.target;
412
+
413
+ let value = DataLeveling( {
414
+ min,max,
415
+ restrict,
416
+ value: rawValue
417
+ } );
418
+ if ( value.formatValue == val_status.formatValue ) return;
419
+
420
+ if ( val_validate.ok ) set_validate( { ok: false,notice: [] } );
421
+ set_status( {
422
+ ...val_status,
423
+ ...value,
424
+ prevValue: val_status.formatValue,
425
+ eventType: 'update',
426
+ eventID: $.uuidGen(),
427
+ caretFrom: Number( selectionStart ),
428
+ caretTo: Number( selectionEnd )
429
+ } );
430
+
431
+ if ( onChange ) onChange( event );
432
+ } }
433
+ { ...others }
434
+ />
435
+ </BoxWrapper>
436
+ );
437
+ }