Skip to content

A self-hosted media server and file management system

feat: install clipboard, table, form, input and select

aminnausinec8856bb8ba0
diff --git a/resources/js/components/cedar-ui/clipboard/ButtonClipboard.vue b/resources/js/components/cedar-ui/clipboard/ButtonClipboard.vue
new file mode 100644
index 00000000..f8362547
--- /dev/null
+++ b/resources/js/components/cedar-ui/clipboard/ButtonClipboard.vue
@@ -0,0 +1,78 @@
+<script setup lang="ts">
+import { useClipboard, cn } from '@aminnausin/cedar-ui';
+import { ButtonIcon } from '../button';
+import { toRef } from 'vue';
+
+const props = defineProps<{
+ text: string;
+ tabindex?: number;
+ buttonStyle?: string;
+ title?: string;
+ variant?: 'default' | 'ghost' | 'transparent';
+}>();
+
+const clipboard = useClipboard(toRef(props.text));
+</script>
+
+<template>
+ <div class="relative z-20 flex items-center">
+ <Transition
+ enter-active-class="transition ease-out duration-300"
+ enter-from-class="opacity-0 translate-x-2"
+ enter-to-class="opacity-100 translate-x-0"
+ leave-active-class="transition ease-in duration-300"
+ leave-from-class="opacity-100 translate-x-0"
+ leave-to-class="opacity-0 translate-x-2"
+ >
+ <div v-if="clipboard.copyNotification.value" class="absolute left-0 flex w-0" v-cloak>
+ <div class="border-success bg-success -ml-1.5 flex h-7 -translate-x-full items-center rounded-md border-r px-3 text-xs text-white">
+ <span>Copied!</span>
+ <div class="absolute top-[7px] -right-3 -mt-px inline-block h-full overflow-hidden">
+ <div class="bg-success size-3 origin-top-left rotate-45 transform border border-transparent"></div>
+ </div>
+ </div>
+ </div>
+ </Transition>
+ <ButtonIcon
+ @click="clipboard.copyToClipboard()"
+ :class="cn('group hover:bg-surface-3 hover:text-foreground-0 text-foreground-1', { 'ring-green-600/50': clipboard.copyNotification.value }, buttonStyle)"
+ :title="title"
+ :variant="variant ?? 'default'"
+ >
+ <template #icon>
+ <svg
+ v-if="clipboard.copyNotification.value"
+ class="text-success size-4 stroke-current"
+ xmlns="http://www.w3.org/2000/svg"
+ fill="none"
+ viewBox="0 0 24 24"
+ stroke-width="1.5"
+ stroke="currentColor"
+ v-cloak
+ >
+ <path stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5" />
+ </svg>
+ <slot v-else v-cloak>
+ <svg class="size-4 stroke-current" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
+ <g fill="none" stroke="none">
+ <path
+ d="M7.75 7.757V6.75a3 3 0 0 1 3-3h6.5a3 3 0 0 1 3 3v6.5a3 3 0 0 1-3 3h-.992"
+ stroke="currentColor"
+ stroke-width="1.5"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ ></path>
+ <path
+ d="M3.75 10.75a3 3 0 0 1 3-3h6.5a3 3 0 0 1 3 3v6.5a3 3 0 0 1-3 3h-6.5a3 3 0 0 1-3-3v-6.5z"
+ stroke="currentColor"
+ stroke-width="1.5"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ ></path>
+ </g>
+ </svg>
+ </slot>
+ </template>
+ </ButtonIcon>
+ </div>
+</template>
diff --git a/resources/js/components/cedar-ui/clipboard/CopyToClipboard.vue b/resources/js/components/cedar-ui/clipboard/CopyToClipboard.vue
new file mode 100644
index 00000000..364bb44d
--- /dev/null
+++ b/resources/js/components/cedar-ui/clipboard/CopyToClipboard.vue
@@ -0,0 +1,80 @@
+<script setup lang="ts">
+import { cn, useClipboard } from '@aminnausin/cedar-ui';
+import { ButtonIcon } from '../button';
+import { TextInput } from '../input';
+import { ref } from 'vue';
+
+const props = defineProps<{ text: string; tabindex?: number }>();
+const text = ref(props.text);
+
+const clipboard = useClipboard(text);
+</script>
+
+<template>
+ <div class="flex h-8 justify-between gap-4">
+ <TextInput name="clipboard-text" class="cursor-text" v-model="text" disabled />
+ <div class="relative z-20 flex items-center">
+ <Transition
+ enter-active-class="transition ease-out duration-300"
+ enter-from-class="opacity-0 translate-x-2"
+ enter-to-class="opacity-100 translate-x-0"
+ leave-active-class="transition ease-in duration-300"
+ leave-from-class="opacity-100 translate-x-0"
+ leave-to-class="opacity-0 translate-x-2"
+ >
+ <div v-if="clipboard.copyNotification.value" class="absolute left-0" v-cloak>
+ <div class="-ml-1.5 flex h-7 -translate-x-full items-center rounded border-r border-green-500 bg-green-500 px-3 text-xs text-white">
+ <span>Copied!</span>
+ <div class="absolute top-1/2 right-0 -mt-px inline-block h-full translate-x-3 -translate-y-2 overflow-hidden">
+ <div class="h-3 w-3 origin-top-left rotate-45 transform border border-transparent bg-green-500"></div>
+ </div>
+ </div>
+ </div>
+ </Transition>
+
+ <ButtonIcon
+ @click="clipboard.copyToClipboard()"
+ :class="
+ cn('group bg-surface-3 hover:text-foreground-0 text-foreground-1 focus:ring-green-600/50', {
+ 'ring-green-600/50': clipboard.copyNotification.value,
+ })
+ "
+ >
+ <template #icon>
+ <svg
+ v-if="clipboard.copyNotification.value"
+ class="text-success size-4 stroke-current"
+ xmlns="http://www.w3.org/2000/svg"
+ fill="none"
+ viewBox="0 0 24 24"
+ stroke-width="1.5"
+ stroke="currentColor"
+ v-cloak
+ >
+ <path stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5" />
+ </svg>
+ <slot v-else v-cloak>
+ <svg class="size-4 stroke-current" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
+ <g fill="none" stroke="none">
+ <path
+ d="M7.75 7.757V6.75a3 3 0 0 1 3-3h6.5a3 3 0 0 1 3 3v6.5a3 3 0 0 1-3 3h-.992"
+ stroke="currentColor"
+ stroke-width="1.5"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ ></path>
+ <path
+ d="M3.75 10.75a3 3 0 0 1 3-3h6.5a3 3 0 0 1 3 3v6.5a3 3 0 0 1-3 3h-6.5a3 3 0 0 1-3-3v-6.5z"
+ stroke="currentColor"
+ stroke-width="1.5"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ ></path>
+ </g>
+ </svg>
+ </slot>
+ </template>
+ </ButtonIcon>
+ </div>
+ </div>
+</template>
diff --git a/resources/js/components/cedar-ui/clipboard/index.ts b/resources/js/components/cedar-ui/clipboard/index.ts
new file mode 100644
index 00000000..24b14885
--- /dev/null
+++ b/resources/js/components/cedar-ui/clipboard/index.ts
@@ -0,0 +1,2 @@
+export { default as ButtonClipboard } from './ButtonClipboard.vue';
+export { default as CopyToClipboard } from './CopyToClipboard.vue';
diff --git a/resources/js/components/cedar-ui/form/BaseForm.vue b/resources/js/components/cedar-ui/form/BaseForm.vue
new file mode 100644
index 00000000..62af6053
--- /dev/null
+++ b/resources/js/components/cedar-ui/form/BaseForm.vue
@@ -0,0 +1,14 @@
+<script setup lang="ts">
+defineProps<{ footerClass?: string }>();
+</script>
+<template>
+ <form class="flex flex-col gap-4">
+ <slot></slot>
+
+ <template v-if="$slots.footer">
+ <footer :class="[`mt-4`, footerClass]">
+ <slot name="footer"></slot>
+ </footer>
+ </template>
+ </form>
+</template>
diff --git a/resources/js/components/cedar-ui/form/FormErrorList.vue b/resources/js/components/cedar-ui/form/FormErrorList.vue
new file mode 100644
index 00000000..63c448ee
--- /dev/null
+++ b/resources/js/components/cedar-ui/form/FormErrorList.vue
@@ -0,0 +1,11 @@
+<script setup lang="ts">
+defineProps<{ errors: Record<string, any>; fieldName?: string }>();
+</script>
+
+<template>
+ <ul class="text-danger text-sm" v-if="fieldName ? !!errors[fieldName] : Object.keys(errors).length > 0">
+ <slot>
+ <li v-for="(item, index) in fieldName ? errors[fieldName] : errors" :key="index">{{ item }}</li>
+ </slot>
+ </ul>
+</template>
diff --git a/resources/js/components/cedar-ui/form/FormInput.vue b/resources/js/components/cedar-ui/form/FormInput.vue
new file mode 100644
index 00000000..e1848636
--- /dev/null
+++ b/resources/js/components/cedar-ui/form/FormInput.vue
@@ -0,0 +1,31 @@
+<script setup lang="ts">
+import type { FormField } from '@aminnausin/cedar-ui';
+
+import { InputShell } from '../input';
+import { cn } from '@aminnausin/cedar-ui';
+
+defineProps<{ field: FormField }>();
+const model = defineModel();
+</script>
+
+<template>
+ <InputShell>
+ <template #input="{ class: inputClass }">
+ <input
+ v-model="model"
+ :type="field.type"
+ :id="field.name"
+ :name="field.name"
+ :title="field.text ?? field.name"
+ :required="field.required"
+ :disabled="field.disabled"
+ :placeholder="field.placeholder"
+ :autocomplete="field.autocomplete"
+ :aria-autocomplete="field.ariaAutocomplete ?? (field.autocomplete ? 'list' : 'none')"
+ :class="cn(inputClass, 'mt-1')"
+ :min="field.min"
+ :max="field.max"
+ />
+ </template>
+ </InputShell>
+</template>
diff --git a/resources/js/components/cedar-ui/form/FormInputLabel.vue b/resources/js/components/cedar-ui/form/FormInputLabel.vue
new file mode 100644
index 00000000..a829e3d8
--- /dev/null
+++ b/resources/js/components/cedar-ui/form/FormInputLabel.vue
@@ -0,0 +1,24 @@
+<script setup lang="ts">
+import type { FormField } from '@aminnausin/cedar-ui';
+
+const props = defineProps<{
+ field: FormField;
+ textSize?: string;
+ class?: string;
+}>();
+</script>
+
+<template>
+ <label
+ v-if="field.text"
+ :for="field.name"
+ :class="[
+ `block leading-none font-medium text-gray-700 dark:text-neutral-200`,
+ textSize ? textSize : 'text-sm',
+ `${props.class ?? ''}`,
+ ]"
+ >
+ {{ field.text }}
+ <p v-if="field.subtext" class="p text-sm/6 text-gray-500 dark:text-gray-400">{{ field.subtext }}</p>
+ </label>
+</template>
diff --git a/resources/js/components/cedar-ui/form/FormItem.vue b/resources/js/components/cedar-ui/form/FormItem.vue
new file mode 100644
index 00000000..c80ecf74
--- /dev/null
+++ b/resources/js/components/cedar-ui/form/FormItem.vue
@@ -0,0 +1,5 @@
+<template>
+ <div class="grid gap-2">
+ <slot> </slot>
+ </div>
+</template>
diff --git a/resources/js/components/cedar-ui/form/FormLabel.vue b/resources/js/components/cedar-ui/form/FormLabel.vue
new file mode 100644
index 00000000..6e821161
--- /dev/null
+++ b/resources/js/components/cedar-ui/form/FormLabel.vue
@@ -0,0 +1,16 @@
+<script setup lang="ts">
+import type { FormLabelProps } from '@aminnausin/cedar-ui';
+
+const props = defineProps<FormLabelProps>();
+</script>
+
+<template>
+ <label v-if="text || $slots" :for="props.for" class="font-medium">
+ <slot>{{ text }}</slot>
+ <slot name="subtext" class="block font-normal">
+ <span v-if="subtext" class="text-foreground-2 block leading-none font-normal">
+ {{ subtext }}
+ </span>
+ </slot>
+ </label>
+</template>
diff --git a/resources/js/components/cedar-ui/form/index.ts b/resources/js/components/cedar-ui/form/index.ts
new file mode 100644
index 00000000..e686ee58
--- /dev/null
+++ b/resources/js/components/cedar-ui/form/index.ts
@@ -0,0 +1,8 @@
+export { default as BaseForm } from './BaseForm.vue';
+
+export { default as FormInput } from './FormInput.vue';
+export { default as FormLabel } from './FormLabel.vue';
+
+export { default as FormItem } from './FormItem.vue';
+
+export { default as FormErrorList } from './FormErrorList.vue';
diff --git a/resources/js/components/cedar-ui/input/InputShell.vue b/resources/js/components/cedar-ui/input/InputShell.vue
new file mode 100644
index 00000000..a8d75f59
--- /dev/null
+++ b/resources/js/components/cedar-ui/input/InputShell.vue
@@ -0,0 +1,28 @@
+<script setup lang="ts">
+import type { InputShellProps } from '@aminnausin/cedar-ui';
+
+import { cn } from '@aminnausin/cedar-ui';
+
+const props = withDefaults(defineProps<InputShellProps>(), { clampText: true });
+</script>
+
+<template>
+ <slot
+ name="input"
+ :class="
+ cn(
+ 'scrollable-input scrollbar-thin',
+ 'transition duration-200 ease-in-out focus:outline-hidden',
+ 'bg-surface-2 placeholder:text-foreground-3 dark:placeholder:text-foreground-2',
+ 'hocus:ring-2 hover:ring-primary-muted focus-visible:ring-primary',
+ { 'line-clamp-1 text-ellipsis whitespace-nowrap': clampText },
+ 'disabled:button-disabled',
+ 'block w-full border-none',
+ 'ring-r-input ring-1', // opinionated border
+ 'rounded-md text-sm shadow-xs', // opinionated input style
+ props.class,
+ )
+ "
+ v-bind="$attrs"
+ />
+</template>
diff --git a/resources/js/components/cedar-ui/input/LabelledTextInput.vue b/resources/js/components/cedar-ui/input/LabelledTextInput.vue
new file mode 100644
index 00000000..cce51c70
--- /dev/null
+++ b/resources/js/components/cedar-ui/input/LabelledTextInput.vue
@@ -0,0 +1,18 @@
+<script setup lang="ts">
+import type { LabelledTextInputProps } from '@aminnausin/cedar-ui';
+
+import { FormLabel } from '../form';
+import { TextInput } from '.';
+
+withDefaults(defineProps<LabelledTextInputProps>(), {
+ id: 'text-input-labelled-' + Math.floor(Math.random() * 10000),
+});
+
+const model = defineModel();
+</script>
+<template>
+ <div class="flex flex-col justify-center gap-2">
+ <FormLabel :for="id" :text="text" :subtext="subtext" :id="`${id}-description`" />
+ <TextInput v-model="model" :id="id" :placeholder="placeholder" :disabled="disabled" :aria-describedby="`${id}-description`" />
+ </div>
+</template>
diff --git a/resources/js/components/cedar-ui/input/TextInput.vue b/resources/js/components/cedar-ui/input/TextInput.vue
new file mode 100644
index 00000000..5f7203cd
--- /dev/null
+++ b/resources/js/components/cedar-ui/input/TextInput.vue
@@ -0,0 +1,31 @@
+<script setup lang="ts">
+import type { TextInputProps } from '@aminnausin/cedar-ui';
+
+import { InputShell } from '.';
+import { ref } from 'vue';
+import { cn } from '@aminnausin/cedar-ui';
+
+const model = defineModel();
+
+const props = defineProps<TextInputProps>();
+const el = ref<HTMLInputElement | null>(null);
+
+defineExpose({ el });
+</script>
+<template>
+ <InputShell>
+ <template #input="{ class: inputClass }">
+ <input
+ ref="el"
+ type="text"
+ v-model="model"
+ :id="id"
+ :minlength="minlength"
+ :maxlength="maxlength"
+ :placeholder="placeholder"
+ :class="cn(inputClass, props.class)"
+ :disabled="disabled"
+ />
+ </template>
+ </InputShell>
+</template>
diff --git a/resources/js/components/cedar-ui/input/index.ts b/resources/js/components/cedar-ui/input/index.ts
new file mode 100644
index 00000000..b60ac271
--- /dev/null
+++ b/resources/js/components/cedar-ui/input/index.ts
@@ -0,0 +1,3 @@
+export { default as LabelledTextInput } from './LabelledTextInput.vue';
+export { default as InputShell } from './InputShell.vue';
+export { default as TextInput } from './TextInput.vue';
diff --git a/resources/js/components/cedar-ui/select/InputSelect.vue b/resources/js/components/cedar-ui/select/InputSelect.vue
new file mode 100644
index 00000000..b9e30515
--- /dev/null
+++ b/resources/js/components/cedar-ui/select/InputSelect.vue
@@ -0,0 +1,233 @@
+<script setup lang="ts">
+// Needs to be converted to TypeScript and use library elements but this is a lot of work
+import type { SelectItem, SelectProps } from '@aminnausin/cedar-ui';
+
+import { onMounted, ref, useTemplateRef, watch } from 'vue';
+import { CedarCheckMark, CedarChevronUpDown } from '../icons';
+import { OnClickOutside } from '@vueuse/components';
+import { useSelect } from '@aminnausin/cedar-ui';
+
+const props = withDefaults(defineProps<SelectProps>(), {
+ class: '',
+ rootClass: '',
+ prefix: '',
+ defaultItem: null,
+ options: () => [
+ {
+ title: 'Title',
+ value: 'title',
+ disabled: false,
+ },
+ {
+ title: 'Date Uploaded',
+ value: 'date',
+ disabled: false,
+ },
+ {
+ title: 'Date released',
+ value: 'date_released',
+ disabled: false,
+ },
+ {
+ title: 'Episode',
+ value: 'episode',
+ disabled: true,
+ },
+ {
+ title: 'Season',
+ value: 'season',
+ disabled: true,
+ },
+ ],
+});
+
+const emit = defineEmits(['selectItem']);
+const selectButton = useTemplateRef('selectButton');
+const selectableItemsList = useTemplateRef('selectableItemsList');
+const selectableItemsRoot = useTemplateRef('selectableItemsRoot');
+const select = useSelect(props.options, { selectableItemsList, selectButton });
+
+const closeFocusOutTimeout = ref<number | null>(null);
+
+const handleItemClick = (item: any, setFocus = true) => {
+ select.selectedItem = item;
+ select.toggleSelect(false);
+ if (setFocus) selectButton.value?.focus();
+ emit('selectItem', select.selectedItem);
+};
+
+const handleItemHover = (item: any) => {
+ select.selectableItemActive = item;
+ select.selectScrollToActiveItem();
+};
+
+const handleItemFocus = (item: any) => {
+ select.selectableItemActive = item;
+};
+
+const handleFocusOut = () => {
+ if (closeFocusOutTimeout.value) {
+ clearTimeout(closeFocusOutTimeout.value);
+ }
+
+ closeFocusOutTimeout.value = window.setTimeout(() => {
+ if (!selectableItemsRoot.value) return;
+
+ const active = document.activeElement;
+
+ if (!selectableItemsRoot.value.contains(active)) {
+ select.toggleSelect(false);
+ }
+ }, 0);
+};
+
+onMounted(() => {
+ if (props.disabled) return;
+
+ if (props.defaultItem != undefined && props.defaultItem < props.options.length && props.defaultItem >= 0) {
+ handleItemClick(props.options[props.defaultItem], false);
+ }
+});
+
+watch(
+ () => props.options,
+ () => {
+ select.selectableItems = props.options;
+ },
+);
+watch(
+ selectButton,
+ () => {
+ if (!selectButton.value) return;
+ select.selectButton = selectButton;
+ },
+ { immediate: true },
+);
+watch(
+ () => selectableItemsList.value,
+ () => {
+ if (!selectableItemsList.value) return;
+ select.selectableItemsList = selectableItemsList;
+ },
+ { immediate: true },
+);
+</script>
+<template>
+ <section :class="[`group relative text-sm`, rootClass]" @focusout="handleFocusOut" ref="selectableItemsRoot">
+ <button
+ @click="select.toggleSelect(!select.selectOpen)"
+ :id="props.name"
+ :title="title ?? 'Make Selection'"
+ :disabled="disabled"
+ :class="[
+ 'transition duration-200 ease-in-out focus:outline-hidden', // Animation
+ 'disabled:button-disabled disabled:button-disabled-pointer', // Disabled
+ 'relative flex items-center justify-between gap-2', // Layout
+ 'cursor-pointer rounded-md shadow-xs', // Style
+ 'h-10 max-h-full w-full py-2 pr-10 pl-3', // Size
+ 'bg-surface-2 hover:bg-surface-3',
+ 'ring-r-button hocus:ring-2 ring-1',
+ { 'hocus:ring-0': select.selectOpen },
+ { 'text-foreground-3': placeholder && !select.selectedItem },
+ 'hover:ring-primary-muted focus:ring-primary focus-within:ring-primary-muted',
+ props.class,
+ ]"
+ ref="selectButton"
+ type="button"
+ >
+ <span class="truncate"
+ >{{
+ //@ts-ignore
+ select.selectedItem ? `${prefix}${select.selectedItem.title}` : placeholder
+ }}
+ </span>
+ <span class="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2">
+ <slot name="selectButtonIcon">
+ <CedarChevronUpDown :class="['text-foreground-2 size-5']" />
+ </slot>
+ </span>
+ </button>
+
+ <Transition enter-from-class="opacity-0" enter-to-class="opacity-100" leave-from-class="opacity-100" leave-to-class="opacity-0">
+ <OnClickOutside
+ v-show="select.selectOpen"
+ :class="[
+ select.selectDropdownPosition == 'top'
+ ? `bottom-0 ${menuMargin?.bottom ?? 'mb-11'}`
+ : `top-0 ${menuMargin?.top ?? 'mt-11'}`,
+ ]"
+ class="bg-overlay-t ring-r-button absolute z-30 mt-1 max-h-56 w-full overflow-clip rounded-md shadow-md ring-1 backdrop-blur-lg transition duration-200 ease-in-out"
+ @trigger="select.toggleSelect(false)"
+ @keydown.esc.stop="
+ (event: Event) => {
+ if (select.selectOpen) {
+ select.toggleSelect(false);
+ event.stopPropagation();
+ }
+ }
+ "
+ @keydown.down.stop.prevent="
+ (event: Event) => {
+ if (select.selectOpen) {
+ select.selectableItemActiveNext();
+ } else {
+ select.toggleSelect(true);
+ }
+ event.preventDefault();
+ }
+ "
+ @keydown.up.stop.prevent="
+ (event: Event) => {
+ if (select.selectOpen) {
+ select.selectableItemActivePrevious();
+ } else {
+ select.toggleSelect(true);
+ }
+ event.preventDefault();
+ }
+ "
+ @keydown.enter.stop.prevent="
+ //@ts-ignore
+ select.selectedItem = select.selectableItemActive;
+ select.toggleSelect(false);
+ console.log('enter');
+ "
+ @keydown.stop="select.selectKeydown($event)"
+ >
+ <ul ref="selectableItemsList" class="scrollbar-thin max-h-56 w-full overflow-auto focus:outline-hidden" role="listbox">
+ <template v-for="item in select.selectableItems" :key="item.value">
+ <li
+ @click="handleItemClick(item)"
+ @keydown.enter="handleItemClick(item)"
+ @keydown.space="handleItemClick(item)"
+ @focus="handleItemFocus(item)"
+ @mousemove="handleItemHover(item)"
+ :id="item.value + '-' + select.selectId"
+ :title="item.title"
+ :data-disabled="item.disabled ? item.disabled : ''"
+ :tabindex="'0'"
+ :class="[
+ {
+ 'bg-overlay-accent dark:bg-overlay-accent/70': select.selectableItemActive === item,
+ 'text-foreground-6': !select.selectableItemActive === item,
+ },
+ 'data-[disabled=true]:button-disabled data-[disabled=true]:button-disabled-pointer relative flex h-full cursor-pointer items-center py-2 pl-8 focus:rounded-md',
+ ]"
+ role="option"
+ :aria-selected="select.selectableItemIsActive(item) ? 'true' : 'false'"
+ >
+ <CedarCheckMark
+ v-if="
+ //@ts-ignore
+ select.selectedItem.value == item.value
+ "
+ class="text-foreground-2 absolute left-0 ml-2 size-4 stroke-current"
+ />
+ <span class="block truncate font-medium">{{ item.title }}</span>
+ </li>
+ </template>
+ </ul>
+ </OnClickOutside>
+ </Transition>
+ </section>
+</template>
diff --git a/resources/js/components/cedar-ui/select/index.ts b/resources/js/components/cedar-ui/select/index.ts
new file mode 100644
index 00000000..80ea39f8
--- /dev/null
+++ b/resources/js/components/cedar-ui/select/index.ts
@@ -0,0 +1 @@
+export { default as InputSelect } from './InputSelect.vue';
diff --git a/resources/js/components/cedar-ui/table/TableBase.vue b/resources/js/components/cedar-ui/table/TableBase.vue
new file mode 100644
index 00000000..63b3d56f
--- /dev/null
+++ b/resources/js/components/cedar-ui/table/TableBase.vue
@@ -0,0 +1,124 @@
+<script setup lang="ts" generic="T extends TableRow">
+import type { TableSortOption, TableProps, TableRow } from '@aminnausin/cedar-ui';
+
+import { PhSortDescendingLight, PhSortAscendingLight } from '../icons';
+import { onMounted, ref, toRef } from 'vue';
+import { cn, useTable } from '@aminnausin/cedar-ui';
+import { InputSelect } from '../select';
+import { ButtonIcon } from '../button';
+import { TextInput } from '../input';
+
+import TableLoadingSpinner from './TableLoadingSpinner.vue';
+import TablePagination from './TablePagination.vue';
+
+const props = withDefaults(defineProps<TableProps<T>>(), {
+ useToolbar: true,
+ usePagination: true,
+ itemsPerPage: 12,
+ selectedID: null,
+ startAscending: true,
+ usePaginationIcons: false,
+ maxVisiblePages: 5,
+ noResultsMessage: 'No Results',
+});
+const { currentPage, itemsPerPage, pageData, setPage } = useTable<T>({ itemsPerPage: props.itemsPerPage, data: toRef(props, 'data') });
+
+const sortAscending = ref(props.startAscending);
+const lastSortKey = ref('');
+
+// Search Query
+const model = defineModel<string>({
+ required: false,
+ default: undefined,
+});
+
+defineSlots<{
+ row(props: { row: T; index: number; selectedID: any }): any;
+}>();
+
+const handleSortChange = (sortKey?: TableSortOption) => {
+ if (sortKey?.value) {
+ lastSortKey.value = sortKey.value;
+ }
+
+ if (!lastSortKey.value) return;
+ props.sortAction?.(lastSortKey.value as keyof T, sortAscending.value ? 1 : -1);
+};
+
+onMounted(() => {
+ if (props.useToolbar && props.sortAction) props.sortAction(lastSortKey.value as keyof T, props.startAscending ? 1 : -1);
+});
+</script>
+
+<template>
+ <section class="flex w-full flex-col gap-3">
+ <section v-if="props.useToolbar" class="flex flex-col justify-center gap-2 sm:flex-row sm:justify-between">
+ <TextInput
+ v-if="model !== undefined"
+ v-model="model"
+ :placeholder="`Search ${props.itemName ? `${props.itemName}...` : ''}`"
+ :id="'table-search'"
+ class="ring-r-button hocus:ring-2 w-full ring-1 sm:w-80"
+ title="Search with..."
+ />
+
+ <div :class="['flex flex-wrap items-end gap-2 sm:flex-nowrap', { 'flex-1': model === undefined }]">
+ <div class="flex w-full flex-1 flex-col gap-2 sm:w-40">
+ <InputSelect
+ :name="'sort'"
+ :placeholder="'Sort by...'"
+ :prefix="'By '"
+ :options="sortingOptions"
+ :defaultItem="0"
+ class="w-full"
+ title="Sort by..."
+ @selectItem="handleSortChange"
+ />
+ </div>
+ <ButtonIcon
+ @click="
+ sortAscending = !sortAscending;
+ handleSortChange();
+ "
+ :title="`Reorder Results...`"
+ :aria-label="`Reorder Results`"
+ class="inline-flex h-full"
+ >
+ <template #icon>
+ <!-- Arrow Pointing Down if ascending and then Up otherwise (arrow shows what to change to ?? idk descending points up actually)-->
+ <PhSortDescendingLight v-if="sortAscending" width="24" height="24" />
+ <PhSortAscendingLight v-else width="24" height="24" />
+ </template>
+ </ButtonIcon>
+ </div>
+ </section>
+ <section :class="cn(useGrid || 'flex w-full flex-wrap gap-2', tableStyles)">
+ <TableLoadingSpinner v-if="loading || pageData?.length === 0" :is-loading="loading" :data-length="pageData?.length" :no-results-message="noResultsMessage" />
+ <template v-else>
+ <template v-for="(row, index) in pageData" :key="row?.id ?? index">
+ <slot name="row" :row="row" :index="index" :selectedID="props.selectedID">
+ <component
+ :is="props.row"
+ :data="row"
+ :index="index"
+ :currentID="props.selectedID ?? null"
+ v-bind="rowAttributes"
+ @clickAction="(...args: any[]) => props.clickAction?.(row?.id, ...args)"
+ @otherAction="(...args: any[]) => props.otherAction?.(row?.id, ...args)"
+ ></component>
+ </slot>
+ </template>
+ </template>
+ </section>
+ <TablePagination
+ v-if="usePagination"
+ :class="paginationClass"
+ :listLength="props.data?.length ?? 0"
+ :itemsPerPage="itemsPerPage"
+ :currentPage="currentPage"
+ :useIcons="props.usePaginationIcons"
+ :max-visible-pages="props.maxVisiblePages"
+ @setPage="setPage"
+ />
+ </section>
+</template>
diff --git a/resources/js/components/cedar-ui/table/TableLoadingSpinner.vue b/resources/js/components/cedar-ui/table/TableLoadingSpinner.vue
new file mode 100644
index 00000000..e45c3dd3
--- /dev/null
+++ b/resources/js/components/cedar-ui/table/TableLoadingSpinner.vue
@@ -0,0 +1,13 @@
+<script setup lang="ts">
+import { SvgSpinners90RingWithBg } from '../icons';
+
+const props = withDefaults(defineProps<{ isLoading?: boolean; noResultsMessage?: string; dataLength?: number }>(), {
+ noResultsMessage: 'No Results',
+});
+</script>
+<template>
+ <div class="text-foreground-2 col-span-full flex w-full items-center justify-center gap-2 text-center text-lg tracking-wider uppercase">
+ <p>{{ isLoading ? '...Loading' : noResultsMessage }}</p>
+ <SvgSpinners90RingWithBg v-show="isLoading" />
+ </div>
+</template>
diff --git a/resources/js/components/cedar-ui/table/TablePagination.vue b/resources/js/components/cedar-ui/table/TablePagination.vue
new file mode 100644
index 00000000..1af10762
--- /dev/null
+++ b/resources/js/components/cedar-ui/table/TablePagination.vue
@@ -0,0 +1,147 @@
+<script setup lang="ts">
+import type { TablePaginationProps } from '@aminnausin/cedar-ui';
+
+import { ProiconsChevronRight, ProiconsChevronLeft } from '../icons';
+import { computed, nextTick, ref } from 'vue';
+
+import TablePaginationButton from './TablePaginationButton.vue';
+
+const props = withDefaults(defineProps<TablePaginationProps>(), {
+ maxVisiblePages: 5,
+});
+const $element = ref<null | HTMLElement>(null);
+
+const emit = defineEmits(['setPage']);
+
+const pageCount = computed(() => {
+ return Math.ceil(props.listLength / props.itemsPerPage);
+});
+
+const pageRange = computed<number | number[]>(() => {
+ const total = pageCount.value;
+ const current = props.currentPage;
+ const maxVisible = props.maxVisiblePages;
+ const edgeThreshold = Math.max(maxVisible - 1, 3);
+ const edgeLength = Math.max(maxVisible - 1, 2);
+ if (total <= maxVisible) return Array.from({ length: total }, (_, i) => i + 1); // Threshold to show all pages at once
+
+ // 1 2 or 3, then show 1 2 3 4... options should be 1 2 or more, so max - 1 or 3 whichever is higher
+ // Threshold (by page selected) to show groups of pages at left end (ie 1, 2, [3], 4, ..., 10)
+ if (current < edgeThreshold) return Array.from({ length: edgeLength }, (_, i) => i + 1); // Number of pages to show with current page on left end (ie [1], 2, 3, 4, ..., 10) (inclusive)
+ if (pageCount.value - current < edgeThreshold - 1) {
+ // 7 8 9 or 10
+ // Threshold (by page selected) to show group of pages at right end (ie 1, ..., 7, [8], 9, 10)
+ let range: number[] = []; // Number of pages to show with current page on left end (ie 1, ..., 7, 8, 9, [10]) (exclusive so 3 items means 3 + 1 [the selected page])
+ for (let i = pageCount.value - edgeLength + 1; i <= pageCount.value; i++) {
+ range = [...range, i]; // Fill an array with all integers from pageCount - (number of items in group - 1) to pageCount
+ }
+
+ return range;
+ }
+
+ return maxVisible >= 5 ? [current - 1, current, current + 1] : [current];
+});
+
+const handleSetPage = async (page: number) => {
+ emit('setPage', page);
+ await nextTick();
+ $element.value?.scrollIntoView({ behavior: 'instant', block: 'end' });
+};
+</script>
+
+<template>
+ <div :class="`flex scroll-mb-12 flex-col flex-wrap items-center gap-2 text-sm sm:flex-row sm:justify-between`" ref="$element">
+ <p class="dark:text-foreground-7 line-clamp-1">
+ Showing
+ <span class="dark:text-foreground-0 font-medium">{{ props.listLength ? props.itemsPerPage * (currentPage - 1) + 1 : 0 }}</span>
+ to
+ <span class="dark:text-foreground-0 font-medium">{{ Math.min(props.itemsPerPage * currentPage, props.listLength) }}</span>
+ of
+ <span class="dark:text-foreground-0 font-medium">{{ listLength }}</span>
+ <!-- Results -->
+ </p>
+ <ul
+ class="bg-overlay-t divide-d text-foreground-7 border-overlay-border flex h-9 items-center divide-x rounded-md border leading-tight"
+ >
+ <TablePaginationButton
+ :pageNumber="-1"
+ :text="'Previous'"
+ :disabled="props.currentPage === 1"
+ @click="handleSetPage(Math.max(1, props.currentPage - 1))"
+ title="Previous Page"
+ >
+ <template #content v-if="useIcons">
+ <ProiconsChevronLeft class="size-4" title="Previous" />
+ </template>
+ <template #content v-else>
+ <span class="hidden sm:block">
+ {{ 'Previous' }}
+ </span>
+ <ProiconsChevronLeft class="size-4 sm:hidden" title="Previous" />
+ </template>
+ </TablePaginationButton>
+
+ <!-- Diff between start and current page is greater than 2 -->
+ <template v-if="pageCount > props.maxVisiblePages && props.currentPage > Math.max(props.maxVisiblePages - 2, 2)">
+ <TablePaginationButton
+ :pageNumber="1"
+ :currentPage="props.currentPage"
+ @click="handleSetPage(1)"
+ :sticky="true"
+ v-if="maxVisiblePages > 3"
+ />
+ <TablePaginationButton
+ :pageNumber="-1"
+ :text="'...'"
+ @click="handleSetPage(Math.floor(currentPage / 2))"
+ :underline="true"
+ :title="`Page ${Math.floor(currentPage / 2)}`"
+ />
+ </template>
+
+ <TablePaginationButton
+ v-for="page in pageRange"
+ :key="page"
+ :pageNumber="page"
+ :currentPage="props.currentPage"
+ @click="handleSetPage(page)"
+ :title="`Page ${page}`"
+ />
+
+ <template v-if="pageCount > props.maxVisiblePages && pageCount - props.currentPage > Math.max(props.maxVisiblePages - 3, 1)">
+ <TablePaginationButton
+ :pageNumber="-1"
+ :text="'...'"
+ :title="`Page ${Math.floor((pageCount - currentPage) / 2 + currentPage)}`"
+ @click="handleSetPage(Math.floor((pageCount - currentPage) / 2 + currentPage))"
+ :underline="true"
+ />
+ <TablePaginationButton
+ :pageNumber="pageCount"
+ :currentPage="props.currentPage"
+ @click="handleSetPage(pageCount)"
+ :sticky="true"
+ v-if="maxVisiblePages > 3"
+ />
+ </template>
+
+ <TablePaginationButton
+ :pageNumber="-1"
+ :text="'Next'"
+ :disabled="props.currentPage === pageCount"
+ @click="handleSetPage(Math.min(pageCount, props.currentPage + 1))"
+ title="Next Page"
+ >
+ <template #content v-if="useIcons">
+ <ProiconsChevronRight class="size-4" title="Next" />
+ </template>
+ <template #content v-else>
+ <span class="hidden sm:block">
+ {{ 'Next' }}
+ </span>
+ <ProiconsChevronRight class="size-4 sm:hidden" title="Next" />
+ </template>
+ </TablePaginationButton>
+ </ul>
+ </div>
+</template>
diff --git a/resources/js/components/cedar-ui/table/TablePaginationButton.vue b/resources/js/components/cedar-ui/table/TablePaginationButton.vue
new file mode 100644
index 00000000..3863585a
--- /dev/null
+++ b/resources/js/components/cedar-ui/table/TablePaginationButton.vue
@@ -0,0 +1,45 @@
+<script setup lang="ts">
+import { cn, type TablePaginationButtonProps } from '@aminnausin/cedar-ui';
+
+import { ButtonBase } from '../button';
+
+const props = withDefaults(defineProps<TablePaginationButtonProps>(), {
+ underline: false,
+ sticky: false,
+ disabled: false,
+});
+</script>
+
+<template>
+ <li :class="{ hidden: currentPage !== pageNumber && !text && !sticky }" class="z-0 h-full md:block">
+ <button-base
+ class="group hover:text-foreground-0 disabled:text-foreground-2 pointer-events-auto! relative inline-flex h-full rounded-none px-3"
+ :class="{
+ 'text-foreground-0 bg-overlay-accent': currentPage === pageNumber,
+ 'hover:bg-overlay-accent': !disabled,
+ }"
+ :disabled="disabled ?? false"
+ :use-size="false"
+ >
+ <slot name="content">
+ <span>
+ {{ text ?? pageNumber }}
+ </span>
+ </slot>
+
+ <span
+ v-if="!text || underline"
+ :class="
+ cn(
+ 'bg-primary group-hover:border-primary absolute bottom-0 -mx-px box-content h-px w-0 translate-y-px border-transparent duration-200 ease-out group-hover:left-0 group-hover:w-full group-hover:border-r group-hover:border-l',
+ {
+ 'left-0 w-full border-r border-l': currentPage === pageNumber,
+ 'left-1/2': currentPage !== pageNumber,
+ },
+ )
+ "
+ >
+ </span>
+ </button-base>
+ </li>
+</template>
diff --git a/resources/js/components/cedar-ui/table/index.ts b/resources/js/components/cedar-ui/table/index.ts
new file mode 100644
index 00000000..7c7da9de
--- /dev/null
+++ b/resources/js/components/cedar-ui/table/index.ts
@@ -0,0 +1,4 @@
+export { default as TablePaginationButton } from './TablePaginationButton.vue';
+export { default as TableLoadingSpinner } from './TableLoadingSpinner.vue';
+export { default as TablePagination } from './TablePagination.vue';
+export { default as TableBase } from './TableBase.vue';