UNPKG

@rocket-sensei/activeadmin-tom_select

Version:

Use Tom Select for searchable selects in Active Admin forms and filters.

392 lines (315 loc) 9.14 kB
/* Tom Select Tailwind CSS styles for ActiveAdmin Searchable Select Credits: - Based on discussion at https://github.com/orchidjs/tom-select/discussions/693 - Original Tailwind styles by @LeZellus (https://github.com/LeZellus) - Updated for Tailwind CSS v4 compatibility */ /* Plugin: Drag & Drop */ .ts-wrapper.plugin-drag_drop.multi > .ts-control > div.ui-sortable-placeholder { @apply visible border-none; } .ts-wrapper.plugin-drag_drop .ui-sortable-placeholder::after { content: "!"; visibility: hidden; } /* Plugin: Checkbox Options */ .plugin-checkbox_options .option input { margin-right: 0.5rem; } /* Plugin: Clear Button */ .plugin-clear_button .clear-button { @apply opacity-0 absolute top-1/2 transform -translate-y-1/2 right-0 cursor-pointer; } .plugin-clear_button.single .clear-button { @apply right-2; } .plugin-clear_button.focus.has-items .clear-button, .plugin-clear_button:hover.has-items .clear-button { @apply opacity-100; } /* Plugin: Dropdown Header */ .ts-wrapper .dropdown-header { @apply relative p-2.5 rounded-t border-b border-gray-300 bg-gray-100; } .ts-wrapper .dropdown-header-close { @apply absolute right-2 top-1/2 opacity-40 -mt-3 leading-5 text-xl; } .ts-wrapper .dropdown-header-close:hover { @apply text-black; } /* Plugin: Dropdown Input */ .plugin-dropdown_input .dropdown-input { @apply block p-2 shadow-none w-full bg-transparent border-b border-gray-300; } /* Plugin: Input Autogrow */ .ts-wrapper.plugin-input_autogrow.has-items .ts-control > input { @apply min-w-0; } .ts-wrapper.plugin-input_autogrow.has-items.focus .ts-control > input { @apply flex; min-width: 4px; } .ts-wrapper.plugin-input_autogrow.has-items.focus .ts-control > input::-webkit-input-placeholder { @apply text-transparent; } .ts-wrapper.plugin-input_autogrow.has-items.focus .ts-control > input::-ms-input-placeholder { @apply text-transparent; } .ts-wrapper.plugin-input_autogrow.has-items.focus .ts-control > input::placeholder { @apply text-transparent; } /* Plugin: Optgroup Columns */ .ts-dropdown.plugin-optgroup_columns .ts-dropdown-content { @apply flex; } .ts-dropdown.plugin-optgroup_columns .optgroup { @apply flex-grow border-t-0 border-r border-gray-100 basis-0 min-w-0; } .ts-dropdown.plugin-optgroup_columns .optgroup:last-child { @apply border-r-0; } .ts-dropdown.plugin-optgroup_columns .optgroup:before { @apply hidden; } .ts-dropdown.plugin-optgroup_columns .optgroup-header { @apply border-t-0; } /* Plugin: Remove Button */ .ts-wrapper.plugin-remove_button .item { @apply inline-flex items-center pr-0; } .ts-wrapper.plugin-remove_button .item .remove { @apply text-inherit no-underline align-middle inline-block p-0 px-1.5 border-l border-gray-300 rounded-r-sm box-border ml-1.5; } .ts-wrapper.plugin-remove_button .item .remove:hover { background: rgba(0, 0, 0, 0.05); } .ts-wrapper.plugin-remove_button .item.active .remove { border-left-color: #cacaca; } .ts-wrapper.plugin-remove_button.disabled .item .remove:hover { background: none; } .ts-wrapper.plugin-remove_button.disabled .item .remove { border-left-color: white; } .ts-wrapper.plugin-remove_button .remove-single { position: absolute; right: 0; top: 0; font-size: 23px; } /* Core Tom Select Styles */ .ts-wrapper { position: relative; } .ts-dropdown, .ts-control, .ts-control input { color: #303030; font-family: inherit; font-size: 13px; line-height: 18px; } /* Control (Input) Styles */ .ts-control, .ts-wrapper.single.input-active .ts-control { @apply bg-white dark:bg-gray-900; cursor: text; } .ts-control { @apply border border-gray-300 dark:border-gray-600 p-2 w-full overflow-hidden relative z-10 box-border shadow-none rounded-sm flex flex-wrap; } .ts-wrapper.multi.has-items .ts-control { padding: 6px 8px 3px; } .full .ts-control { @apply bg-gray-50 dark:bg-gray-900 dark:text-gray-100; } .disabled .ts-control, .disabled .ts-control * { @apply cursor-default; } .focus .ts-control { @apply shadow-none border-indigo-500 ring-1 ring-indigo-500; } .ts-control > * { @apply align-baseline inline-block; } /* Multi-select Items */ .ts-wrapper.multi .ts-control > div { @apply cursor-pointer m-0 mr-1 my-1 px-2 py-1 bg-gray-100 text-gray-800 border-0 rounded-sm; } .ts-wrapper.multi .ts-control > div.active { @apply bg-gray-200 text-gray-900; } .ts-wrapper.multi.disabled .ts-control > div, .ts-wrapper.multi.disabled .ts-control > div.active { @apply text-gray-400 bg-gray-50 border-0; } /* Selected items display */ .ts-control .item { @apply inline-flex items-center; } /* Input Field */ .ts-control > input { @apply inline-block p-0 min-h-0 max-w-full m-0 indent-0 border-0 bg-transparent flex-grow select-auto placeholder-gray-400 dark:placeholder-gray-600; min-width: 7rem; max-height: none !important; box-shadow: none !important; outline: none !important; } .ts-control > input::-ms-clear { @apply hidden; } .ts-control > input:focus { @apply outline-none; } .has-items .ts-control > input { margin: 0 4px !important; } /* RTL Support */ .ts-control.rtl { @apply text-right; } .ts-control.rtl.single .ts-control:after { @apply absolute right-auto; content: ''; left: 15px; } .ts-control.rtl .ts-control > input { margin: 0 4px 0 -2px !important; } /* Disabled State */ .disabled .ts-control { @apply opacity-50 bg-gray-50 cursor-not-allowed; } .input-hidden .ts-control > input { @apply opacity-0 absolute; left: -10000px; } /* Dropdown Styles */ .ts-dropdown { @apply absolute top-full left-0 w-full z-50 border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-900 mt-1 box-border rounded-sm shadow-sm overflow-hidden; } .ts-dropdown [data-selectable] { @apply cursor-pointer overflow-hidden; } .ts-dropdown [data-selectable] .highlight { background: rgba(125, 168, 208, 0.2); border-radius: 1px; } .ts-dropdown .option, .ts-dropdown .optgroup-header, .ts-dropdown .no-results, .ts-dropdown .create { @apply px-3 py-2; } .ts-dropdown .option, .ts-dropdown [data-disabled], .ts-dropdown [data-disabled] [data-selectable].option { cursor: inherit; opacity: 0.5; } .ts-dropdown [data-selectable].option { @apply opacity-100 cursor-pointer text-gray-900 dark:text-gray-100; } .ts-dropdown .optgroup:first-child .optgroup-header { @apply border-t-0; } .ts-dropdown .optgroup-header { @apply cursor-default bg-gray-50 text-gray-700 font-semibold text-xs uppercase tracking-wider; } /* Hover and Active States */ .ts-dropdown .create:hover, .ts-dropdown .option:hover, .ts-dropdown .active { @apply bg-indigo-50 dark:bg-gray-800 text-indigo-900 dark:text-gray-100; } .ts-dropdown .create:hover.create, .ts-dropdown .option:hover.create, .ts-dropdown .active.create { @apply text-gray-600; } .ts-dropdown .create { @apply text-gray-500; } /* Loading Spinner */ .ts-dropdown .spinner { @apply inline-block w-7 h-7 m-1 mx-2; } .ts-dropdown .spinner:after { @apply block w-6 h-6 m-1 rounded-full border-4 border-gray-300; content: " "; border-color: #3b82f6 transparent #3b82f6 transparent; animation: lds-dual-ring 1.2s linear infinite; } @keyframes lds-dual-ring { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } /* Dropdown Content Scrolling */ .ts-dropdown-content { @apply overflow-y-auto overflow-x-hidden max-h-52; -webkit-overflow-scrolling: touch; scroll-behavior: smooth; } /* Accessibility Helper */ .ts-hidden-accessible { @apply border-0 overflow-hidden p-0 absolute whitespace-nowrap; width: 1px !important; height: 1px !important; clip: rect(0 0 0 0) !important; clip-path: inset(50%) !important; } /* Single Select Arrow */ .ts-wrapper.single .ts-control:not(.dropdown-active) { background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e"); background-position: right 0.5rem center; background-repeat: no-repeat; background-size: 1.5em 1.5em; padding-right: 2.5rem; } /* Override ActiveAdmin's width: 100% on inputs inside Tom Select */ .ts-wrapper.single .ts-control, .ts-wrapper.single .ts-control input { width: auto !important; } /* ActiveAdmin Specific Overrides */ .searchable_select.input .ts-wrapper { min-width: 30%; display: inline-block; } .searchable_select.input .ts-control { margin-top: 0; } /* Filter Form Specific Styles */ .filter_form .searchable_select.input .ts-wrapper { width: 100%; } /* Hide Duplicate Elements */ .ts-wrapper + .ts-control { display: none; } /* Dark Mode Support */ .dark .ts-control { @apply bg-gray-800 border-gray-600 text-gray-100; } .dark .ts-dropdown { @apply bg-gray-800 border-gray-600; } .dark .ts-dropdown .option { @apply text-gray-100; } .dark .ts-dropdown .option:hover, .dark .ts-dropdown [data-selectable].active { @apply bg-gray-700 text-white; } .dark .ts-wrapper.multi .ts-control > div { @apply bg-gray-700 text-gray-100; }