From d5afecaaf18b835e4294743d1283feb49bdbb55c Mon Sep 17 00:00:00 2001 From: DTCurrie Date: Mon, 28 Aug 2023 15:46:14 -0400 Subject: [PATCH] Add plugins to tailwind theme in core, move scrollbar styles to new utility classes --- packages/core/plugins.ts | 87 +++++++++++++++++++ .../core/src/lib/select/select-menu.svelte | 24 +---- packages/core/svelte.config.js | 1 + packages/core/tailwind.config.ts | 2 + packages/core/theme.ts | 4 +- 5 files changed, 94 insertions(+), 24 deletions(-) create mode 100644 packages/core/plugins.ts diff --git a/packages/core/plugins.ts b/packages/core/plugins.ts new file mode 100644 index 000000000..c3684aca5 --- /dev/null +++ b/packages/core/plugins.ts @@ -0,0 +1,87 @@ +import plugin from 'tailwindcss/plugin'; +import type { OptionalConfig } from 'tailwindcss/types/config'; + +export const plugins = [ + plugin(({ addUtilities, matchUtilities, theme }) => { + addUtilities({ + '.scrollbar-thin': { + 'scrollbar-width': 'thin', + }, + }); + + matchUtilities( + { + scrollbar: (value: string) => ({ + scrollbarColor: value, + }), + }, + { values: theme('colors') ?? {} } + ); + + matchUtilities( + { + 'scrollbar-w': (value: string) => ({ + '&::-webkit-scrollbar': { + width: value, + }, + }), + }, + { values: theme('spacing') ?? {} } + ); + + matchUtilities( + { + 'scrollbar-track': (value: string) => ({ + '&::-webkit-scrollbar-track': { + background: value, + }, + }), + }, + { values: theme('colors') ?? {} } + ); + + matchUtilities( + { + 'scrollbar-thumb': (value: string) => ({ + '&::-webkit-scrollbar-thumb': { + backgroundColor: value, + }, + }), + }, + { values: theme('colors') ?? {} } + ); + + matchUtilities( + { + 'scrollbar-thumb-border': (value: string) => ({ + '&::-webkit-scrollbar-thumb': { + borderRadius: value, + }, + }), + }, + { values: theme('borderRadius') ?? {} } + ); + + matchUtilities( + { + 'scrollbar-thumb-border': (value: string) => ({ + '&::-webkit-scrollbar-thumb': { + borderWidth: value, + }, + }), + }, + { values: theme('borderWidth') ?? {} } + ); + + matchUtilities( + { + 'scrollbar-thumb-border': (value: string) => ({ + '&::-webkit-scrollbar-thumb': { + borderColor: value, + }, + }), + }, + { values: theme('borderColor') ?? {} } + ); + }), +] satisfies OptionalConfig['plugins']; diff --git a/packages/core/src/lib/select/select-menu.svelte b/packages/core/src/lib/select/select-menu.svelte index 2f3946212..12b27f24a 100644 --- a/packages/core/src/lib/select/select-menu.svelte +++ b/packages/core/src/lib/select/select-menu.svelte @@ -28,7 +28,7 @@ export let heading = ''; {/if}