@colisweb/rescript-toolkit 2.17.0 → 2.18.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.18.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,25 @@ 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 defaultMessage="Hide password" />
168
+ : <ReactIntl.FormattedMessage defaultMessage="Show password" />}>
169
+ <button
170
+ type_="button"
171
+ className="p-1 bg-neutral-300 rounded-r border border-gray-300 text-neutral-800"
172
+ onClick={_ => setShowPassword(v => !v)}>
173
+ {showPassword
174
+ ? <BsReactIcons.AiFillEyeInvisible size={26} />
175
+ : <BsReactIcons.AiFillEye size={26} />}
176
+ </button>
177
+ </Toolkit__Ui_Tooltip>
178
+ | _ => React.null
179
+ }
180
+ })}
156
181
  {inputRightAddon->Option.getWithDefault(React.null)}
157
182
  </div>
158
183
  </div>
@@ -160,5 +185,6 @@ module Make = (StateLenses: Config) => {
160
185
  </>
161
186
  }}
162
187
  />
188
+ }
163
189
  }
164
190
  }
@@ -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
+ }