@colisweb/rescript-toolkit 2.17.0 → 2.19.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colisweb/rescript-toolkit",
3
- "version": "2.17.0",
3
+ "version": "2.19.0",
4
4
  "scripts": {
5
5
  "clean": "rescript clean",
6
6
  "build": "rescript build",
@@ -86,6 +86,7 @@
86
86
  "raw-loader": "4.0.2",
87
87
  "react": "17.0.2",
88
88
  "react-dom": "17.0.2",
89
+ "react-intl": "5.24.7",
89
90
  "react-is": "17.0.2",
90
91
  "sass": "1.45.0"
91
92
  }
@@ -100,9 +100,13 @@ module Make = (StateLenses: Config) => {
100
100
  ~inputRightAddon=?,
101
101
  ~errorClassName=?,
102
102
  ~optionalMessage: option<React.element>=?,
103
- ) =>
103
+ ) => {
104
+ let (showPassword, setShowPassword) = React.useState(() => false)
105
+ let isPasswordType = type_->Option.mapWithDefault(false, type_ => type_ === "password")
106
+
104
107
  <Form.Field
105
108
  field
109
+ key={showPassword->string_of_bool}
106
110
  render={({handleChange, error, value, validate, state}) => {
107
111
  let isInvalid = error->Option.isSome
108
112
 
@@ -137,12 +141,14 @@ module Make = (StateLenses: Config) => {
137
141
  <Toolkit__Ui.TextInput
138
142
  className={cx([
139
143
  inputClassName,
140
- inputRightAddon->Option.isSome ? "rounded-r-none" : "",
144
+ inputRightAddon->Option.isSome || isPasswordType ? "rounded-r-none" : "",
141
145
  ])}
142
146
  id
143
147
  value
144
148
  ?name
145
- ?type_
149
+ type_=?{type_->Option.map(type_ =>
150
+ type_ === "password" && showPassword ? "text" : type_
151
+ )}
146
152
  ?disabled
147
153
  ?placeholder
148
154
  ?autoFocus
@@ -153,6 +159,29 @@ module Make = (StateLenses: Config) => {
153
159
  onChange
154
160
  onBlur
155
161
  />
162
+ {type_->Option.mapWithDefault(React.null, type_ => {
163
+ switch type_ {
164
+ | "password" =>
165
+ <Toolkit__Ui_Tooltip
166
+ label={showPassword
167
+ ? <ReactIntl.FormattedMessage
168
+ id="toolkit.hidePassword" defaultMessage="Hide password"
169
+ />
170
+ : <ReactIntl.FormattedMessage
171
+ id="toolkit.showPassword" defaultMessage="Show password"
172
+ />}>
173
+ <button
174
+ type_="button"
175
+ className="p-1 bg-neutral-300 rounded-r border border-gray-300 text-neutral-800"
176
+ onClick={_ => setShowPassword(v => !v)}>
177
+ {showPassword
178
+ ? <BsReactIcons.AiFillEyeInvisible size={26} />
179
+ : <BsReactIcons.AiFillEye size={26} />}
180
+ </button>
181
+ </Toolkit__Ui_Tooltip>
182
+ | _ => React.null
183
+ }
184
+ })}
156
185
  {inputRightAddon->Option.getWithDefault(React.null)}
157
186
  </div>
158
187
  </div>
@@ -160,5 +189,6 @@ module Make = (StateLenses: Config) => {
160
189
  </>
161
190
  }}
162
191
  />
192
+ }
163
193
  }
164
194
  }
@@ -24,6 +24,7 @@ let make = (
24
24
  ~checked=?,
25
25
  ~className="",
26
26
  ~size: size=#sm,
27
+ ~checkboxClassName="",
27
28
  ) =>
28
29
  <label
29
30
  className={cx([
@@ -58,6 +59,7 @@ let make = (
58
59
  | #md => "w-8 h-8"
59
60
  | #lg => "w-10 h-10"
60
61
  },
62
+ checkboxClassName,
61
63
  ])}>
62
64
  <BsReactIcons.FaCheck
63
65
  className="transform transition-all ease-in-out"
@@ -10,4 +10,5 @@ let make: (
10
10
  ~checked: bool=?,
11
11
  ~className: string=?,
12
12
  ~size: size=?,
13
+ ~checkboxClassName: string=?,
13
14
  ) => React.element
@@ -5899,3 +5899,12 @@ module IoIosCloseCircle = {
5899
5899
  external make: (~size: int=?, ~color: string=?, ~className: string=?) => React.element =
5900
5900
  "IoIosCloseCircle"
5901
5901
  }
5902
+
5903
+ module AiFillEyeInvisible = {
5904
+ @module("react-icons/ai") @react.component
5905
+ external make: (~size: int=?) => React.element = "AiFillEyeInvisible"
5906
+ }
5907
+ module AiFillEye = {
5908
+ @module("react-icons/ai") @react.component
5909
+ external make: (~size: int=?) => React.element = "AiFillEye"
5910
+ }