From 863054b044cb178dc9f90d5c2d66bbd820c8d7d5 Mon Sep 17 00:00:00 2001 From: Martin Artnik Date: Wed, 3 May 2023 12:37:14 +0200 Subject: [PATCH] Implement basic select/search-select components in vue [SCI-8249] --- app/assets/stylesheets/shared/select.scss | 101 ++++++++++++++++++++ app/javascript/vue/shared/select.vue | 82 ++++++++++++++++ app/javascript/vue/shared/select_search.vue | 77 +++++++++++++++ config/locales/en.yml | 1 + 4 files changed, 261 insertions(+) create mode 100644 app/assets/stylesheets/shared/select.scss create mode 100644 app/javascript/vue/shared/select.vue create mode 100644 app/javascript/vue/shared/select_search.vue diff --git a/app/assets/stylesheets/shared/select.scss b/app/assets/stylesheets/shared/select.scss new file mode 100644 index 000000000..f31a78c6a --- /dev/null +++ b/app/assets/stylesheets/shared/select.scss @@ -0,0 +1,101 @@ +.sn-select { + border: 1px solid; + border-color: var(--sn-grey); + border-radius: 4px; + cursor: pointer; + padding: .5em; + position: relative; + + &.sn-select--blank { + .sn-select__value { + color: var(--sn-grey); + font-style: italic; + } + } + + &.sn-select--search.sn-select--open { + .sn-select__value { + display: none; + } + } + + .sn-select__value { + all: unset; + overflow: hidden; + padding-right: 1em; + text-overflow: ellipsis; + white-space: nowrap; + width: calc(100% - 1em); + } + + &:hover { + background: var(--sn-sleepy-grey); + } + + &.disabled { + background: var(--sn-sleepy-grey); + cursor: default; + pointer-events: none; + + .caret { + border-top-color: var(--sn-grey); + } + } + + .sn-select__options { + display: none; + } + + .sn-select__caret { + position: absolute; + right: 1em; + top: 1.1em; + } + + .sn-select__search-input { + background: transparent; + border: 0; + display: none; + outline: 0; + } + + &.sn-select--open { + background: $color-white; + border-bottom-left-radius: 0; + border-bottom-right-radius: 0; + border-color: var(--sn-science-blue); + + .sn-select__search-input { + display: block; + } + + .sn-select__caret { + transform: rotate(180deg); + } + + .sn-select__options { + background: var(--sn-white); + border-bottom-left-radius: 4px; + border-bottom-right-radius: 4px; + box-shadow: $flyout-shadow; + display: block; + left: 0; + max-height: 300px; + overflow: hidden; + overflow-y: scroll; + position: absolute; + top: 2.5em; + width: 100%; + z-index: 9999; + } + + .sn-select__option { + padding: .5em; + } + + .sn-select__option:hover { + background: var(--sn-blue); + color: var(--sn-white); + } + } +} diff --git a/app/javascript/vue/shared/select.vue b/app/javascript/vue/shared/select.vue new file mode 100644 index 000000000..9cb048dfa --- /dev/null +++ b/app/javascript/vue/shared/select.vue @@ -0,0 +1,82 @@ + + + diff --git a/app/javascript/vue/shared/select_search.vue b/app/javascript/vue/shared/select_search.vue new file mode 100644 index 000000000..44827b109 --- /dev/null +++ b/app/javascript/vue/shared/select_search.vue @@ -0,0 +1,77 @@ + + + diff --git a/config/locales/en.yml b/config/locales/en.yml index 431ae226b..7e9ad662a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3367,6 +3367,7 @@ en: remove: "Remove" clone_label: "Clone" download: "Download" + select: "Select" # In order to use the strings 'yes' and 'no' as keys, you need to wrap them with quotes 'yes': "Yes" 'no': "No"