0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-23 23:18:48 -05:00

💄 Refactor usability of input fields

This commit is contained in:
Andrés Moya 2020-06-17 12:49:00 +02:00 committed by Andrey Antukh
parent 8c49d11026
commit b7bf7c8baf
2 changed files with 104 additions and 86 deletions

View file

@ -86,21 +86,18 @@ textarea {
.custom-input {
display: flex;
flex-direction: column;
label {
font-size: $fs10;
color: $color-gray-30;
}
position: relative;
input {
background-color: $color-white;
border-radius: 2px;
border: 1px solid $color-gray-20;
color: $color-gray-60;
font-size: $fs12;
height: 40px;
margin: 0;
padding: 15px 15px 0 15px;
width: 100%;
border: 0px;
padding: 0px;
margin: 0px;
background-color: transparent;
}
// Makes the background for autocomplete white
@ -111,38 +108,77 @@ textarea {
-webkit-box-shadow: 0 0 0 30px $color-white inset !important;
}
.input-container {
display: flex;
flex-direction: row;
label {
font-size: $fs10;
color: $color-gray-30;
position: absolute;
left: 15px;
top: 6px;
}
background-color: $color-white;
border-radius: 2px;
border: 1px solid $color-gray-20;
height: 40px;
padding-left: 15px;
padding-right: 15px;
&.invalid {
&.invalid {
input {
border-color: $color-danger;
label {
color: $color-danger;
}
}
label {
color: $color-danger;
}
}
&.valid {
&.valid {
input {
border-color: $color-success;
}
}
&.focus {
&.focus {
input {
border-color: $color-gray-60;
}
}
&.disabled {
&.disabled {
input {
background-color: lighten($color-gray-10, 5%);
user-select: none;
}
}
&.empty {
input {
padding-top: 0;
}
label {
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
width: 1px;
}
}
&.with-icon {
input {
padding-right: 50px;
}
}
.help-icon {
position: absolute;
right: 15px;
top: 12px;
display: flex;
justify-content: center;
align-items: center;
svg {
fill: $color-gray-30;
width: 15px;
height: 15px;
}
}
.hint {
padding: 4px;
font-size: $fs10;
@ -153,28 +189,6 @@ textarea {
padding: 4px;
font-size: $fs10;
}
.main-content {
flex-grow: 1;
display: flex;
flex-direction: column;
justify-content: center;
padding-top: 6px;
padding-bottom: 6px;
}
.help-icon {
display: flex;
justify-content: center;
align-items: center;
padding-left: 10px;
svg {
fill: $color-gray-30;
width: 15px;
height: 15px;
}
}
}
.custom-select {

View file

@ -23,20 +23,36 @@
(mf/defc input
[{:keys [type label help-icon disabled name form hint] :as props}]
(let [form (mf/use-ctx form-ctx)
(let [form (mf/use-ctx form-ctx)
type' (mf/use-state type)
focus? (mf/use-state false)
locale (mf/deref i18n/locale)
type' (mf/use-state type)
focus? (mf/use-state false)
locale (mf/deref i18n/locale)
touched? (get-in form [:touched name])
error (get-in form [:errors name])
touched? (get-in form [:touched name])
error (get-in form [:errors name])
value (get-in form [:data name] "")
help-icon' (cond
(and (= type "password")
(= @type' "password"))
i/eye
(and (= type "password")
(= @type' "text"))
i/eye-closed
:else
help-icon)
klass (dom/classnames
:focus @focus?
:valid (and touched? (not error))
:invalid (and touched? error)
:disabled disabled)
:focus @focus?
:valid (and touched? (not error))
:invalid (and touched? error)
:disabled disabled
:empty (str/empty? value)
:with-icon (not (nil? help-icon')))
swap-text-password
(fn []
@ -54,8 +70,6 @@
(when-not (get-in form [:touched name])
(swap! form assoc-in [:touched name] true)))
value (get-in form [:data name] "")
props (-> props
(dissoc :help-icon :form)
(assoc :value value
@ -67,32 +81,22 @@
(obj/clj->props))]
[:div.field.custom-input
[:div.input-container {:class klass}
[:div.main-content
(when-not (str/empty? value)
[:label label])
[:> :input props]]
[:div.help-icon
{:style {:cursor "pointer"}
:on-click (when (= "password" type)
swap-text-password)}
(cond
(and (= type "password")
(= @type' "password"))
i/eye
{:class klass}
[:*
[:label label]
[:> :input props]
(when help-icon'
[:div.help-icon
{:style {:cursor "pointer"}
:on-click (when (= "password" type)
swap-text-password)}
help-icon'])
(cond
(and touched? (:message error))
[:span.error (t locale (:message error))]
(and (= type "password")
(= @type' "text"))
i/eye-closed
:else
help-icon)]]
(cond
(and touched? (:message error))
[:span.error (t locale (:message error))]
(string? hint)
[:span.hint hint])]))
(string? hint)
[:span.hint hint])]]))
(mf/defc select
[{:keys [options label name form default]