mirror of
https://github.com/versia-pub/frontend.git
synced 2025-12-06 08:28:20 +01:00
feat: ✨ Make composer work again
This commit is contained in:
parent
4dfbd845d3
commit
294740c97f
|
|
@ -1,47 +1,216 @@
|
||||||
<template>
|
<template>
|
||||||
<Textarea :placeholder="chosenSplash" class="!border-none !ring-0 !outline-none rounded-none p-0 max-h-full min-h-48 !ring-offset-0" />
|
<Input v-model:model-value="state.contentWarning" v-if="state.sensitive"
|
||||||
|
placeholder="Put your content warning here" />
|
||||||
|
|
||||||
|
<Textarea :placeholder="chosenSplash" v-model:model-value="state.content"
|
||||||
|
class="!border-none !ring-0 !outline-none rounded-none p-0 max-h-full min-h-48 !ring-offset-0"
|
||||||
|
:disabled="sending" />
|
||||||
|
|
||||||
<DialogFooter class="items-center flex-row">
|
<DialogFooter class="items-center flex-row">
|
||||||
|
<TooltipProvider>
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger as="div">
|
||||||
<Button variant="ghost" size="icon">
|
<Button variant="ghost" size="icon">
|
||||||
<AtSign class="!size-5" />
|
<AtSign class="!size-5" />
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="ghost" size="icon">
|
</TooltipTrigger>
|
||||||
|
<TooltipContent>
|
||||||
|
<p>Mention someone</p>
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</TooltipProvider>
|
||||||
|
<TooltipProvider>
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger as="div">
|
||||||
|
<Toggle variant="default" size="sm" :pressed="state.contentType === 'text/markdown'"
|
||||||
|
@update:pressed="i => state.contentType = i ? 'text/plain' : 'text/markdown'">
|
||||||
<LetterText class="!size-5" />
|
<LetterText class="!size-5" />
|
||||||
|
</Toggle>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent>
|
||||||
|
<p>Enable Markdown</p>
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</TooltipProvider>
|
||||||
|
<Select v-model:model-value="state.visibility">
|
||||||
|
<SelectTrigger :as-child="true" :disabled="relation?.type === 'edit'">
|
||||||
|
<Button variant="ghost" size="icon">
|
||||||
|
<component :is="visibilities[state.visibility].icon" class="!size-5" />
|
||||||
</Button>
|
</Button>
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem v-for="(v, k) in visibilities" :key="k" @click="state.visibility = k" :value="k">
|
||||||
|
<div class="flex flex-row gap-4 items-center w-full justify-between">
|
||||||
|
<div class="flex flex-col gap-1">
|
||||||
|
<span class="font-semibold">{{ v.name }}</span>
|
||||||
|
<span>{{ v.text }}</span>
|
||||||
|
</div>
|
||||||
|
<component :is="v.icon" class="!size-5" />
|
||||||
|
</div>
|
||||||
|
</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<TooltipProvider>
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger as="div">
|
||||||
<Button variant="ghost" size="icon">
|
<Button variant="ghost" size="icon">
|
||||||
<Smile class="!size-5" />
|
<Smile class="!size-5" />
|
||||||
</Button>
|
</Button>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent>
|
||||||
|
<p>Insert emoji</p>
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</TooltipProvider>
|
||||||
|
<TooltipProvider>
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger as="div">
|
||||||
<Button variant="ghost" size="icon">
|
<Button variant="ghost" size="icon">
|
||||||
<FilePlus2 class="!size-5" />
|
<FilePlus2 class="!size-5" />
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="ghost" size="icon">
|
</TooltipTrigger>
|
||||||
|
<TooltipContent>
|
||||||
|
<p>Attach a file</p>
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</TooltipProvider>
|
||||||
|
<TooltipProvider>
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger as="div">
|
||||||
|
<Toggle variant="default" size="sm" @update:pressed="i => state.sensitive = i">
|
||||||
<TriangleAlert class="!size-5" />
|
<TriangleAlert class="!size-5" />
|
||||||
</Button>
|
</Toggle>
|
||||||
<Button type="submit" size="lg" class="ml-auto">
|
</TooltipTrigger>
|
||||||
|
<TooltipContent>
|
||||||
|
<p>Mark as sensitive</p>
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</TooltipProvider>
|
||||||
|
<Button type="submit" size="lg" class="ml-auto" :disabled="sending" @click="submit">
|
||||||
|
<Loader v-if="sending" class="!size-5 animate-spin" />
|
||||||
{{ relation?.type === "edit" ? "Save" : "Send" }}
|
{{ relation?.type === "edit" ? "Save" : "Send" }}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
import type { ResponseError } from "@versia/client";
|
||||||
import type { Status } from "@versia/client/types";
|
import type { Status } from "@versia/client/types";
|
||||||
import {
|
import {
|
||||||
AtSign,
|
AtSign,
|
||||||
FilePlus2,
|
FilePlus2,
|
||||||
|
Globe,
|
||||||
LetterText,
|
LetterText,
|
||||||
|
Loader,
|
||||||
|
Lock,
|
||||||
|
LockOpen,
|
||||||
Smile,
|
Smile,
|
||||||
TriangleAlert,
|
TriangleAlert,
|
||||||
} from "lucide-vue-next";
|
} from "lucide-vue-next";
|
||||||
|
import { SelectTrigger } from "radix-vue";
|
||||||
|
import { toast } from "vue-sonner";
|
||||||
|
import { Select, SelectContent, SelectItem } from "~/components/ui/select";
|
||||||
import { Button } from "../ui/button";
|
import { Button } from "../ui/button";
|
||||||
|
import { Input } from "../ui/input";
|
||||||
import { Textarea } from "../ui/textarea";
|
import { Textarea } from "../ui/textarea";
|
||||||
|
import { Toggle } from "../ui/toggle";
|
||||||
|
|
||||||
defineProps<{
|
const { Control_Enter, Command_Enter } = useMagicKeys();
|
||||||
|
|
||||||
|
watch([Control_Enter, Command_Enter], () => {
|
||||||
|
if (sending.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
submit();
|
||||||
|
});
|
||||||
|
|
||||||
|
const { relation } = defineProps<{
|
||||||
relation?: {
|
relation?: {
|
||||||
type: "reply" | "reblog" | "edit";
|
type: "reply" | "quote" | "edit";
|
||||||
note: Status;
|
note: Status;
|
||||||
};
|
};
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
|
const state = reactive({
|
||||||
|
content: "",
|
||||||
|
sensitive: false,
|
||||||
|
contentWarning: "",
|
||||||
|
contentType: "text/markdown" as "text/markdown" | "text/plain",
|
||||||
|
visibility: "public" as Status["visibility"],
|
||||||
|
files: [] as {
|
||||||
|
apiId?: string;
|
||||||
|
file: File;
|
||||||
|
alt: string;
|
||||||
|
uploading: boolean;
|
||||||
|
updating: boolean;
|
||||||
|
}[],
|
||||||
|
});
|
||||||
|
const sending = ref(false);
|
||||||
|
|
||||||
const splashes = useConfig().COMPOSER_SPLASHES;
|
const splashes = useConfig().COMPOSER_SPLASHES;
|
||||||
const chosenSplash = splashes[Math.floor(Math.random() * splashes.length)];
|
const chosenSplash = splashes[Math.floor(Math.random() * splashes.length)];
|
||||||
|
|
||||||
|
const submit = async () => {
|
||||||
|
sending.value = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (relation?.type === "edit") {
|
||||||
|
await client.value.editStatus(relation.note.id, {
|
||||||
|
status: state.content,
|
||||||
|
content_type: state.contentType,
|
||||||
|
sensitive: state.sensitive,
|
||||||
|
spoiler_text: state.sensitive
|
||||||
|
? state.contentWarning
|
||||||
|
: undefined,
|
||||||
|
media_ids: state.files
|
||||||
|
.map((f) => f.apiId)
|
||||||
|
.filter((f) => f !== undefined),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await client.value.postStatus(state.content, {
|
||||||
|
content_type: state.contentType,
|
||||||
|
sensitive: state.sensitive,
|
||||||
|
spoiler_text: state.sensitive ? state.contentWarning : undefined,
|
||||||
|
media_ids: state.files
|
||||||
|
.map((f) => f.apiId)
|
||||||
|
.filter((f) => f !== undefined),
|
||||||
|
quote_id: relation?.type === "quote" ? relation.note.id : undefined,
|
||||||
|
in_reply_to_id:
|
||||||
|
relation?.type === "reply" ? relation.note.id : undefined,
|
||||||
|
visibility: state.visibility,
|
||||||
|
});
|
||||||
|
|
||||||
|
useEvent("composer:close");
|
||||||
|
} catch (_e) {
|
||||||
|
const e = _e as ResponseError;
|
||||||
|
toast.error(e.message);
|
||||||
|
} finally {
|
||||||
|
sending.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const visibilities = {
|
||||||
|
public: {
|
||||||
|
icon: Globe,
|
||||||
|
name: "Public",
|
||||||
|
text: "Can be seen by anyone.",
|
||||||
|
},
|
||||||
|
unlisted: {
|
||||||
|
icon: LockOpen,
|
||||||
|
name: "Unlisted",
|
||||||
|
text: "Can be seen by anyone with the link.",
|
||||||
|
},
|
||||||
|
private: {
|
||||||
|
icon: Lock,
|
||||||
|
name: "Private",
|
||||||
|
text: "Can only be seen by your followers.",
|
||||||
|
},
|
||||||
|
direct: {
|
||||||
|
icon: AtSign,
|
||||||
|
name: "Direct",
|
||||||
|
text: "Can only be seen by mentioned users.",
|
||||||
|
},
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -8,6 +8,10 @@ useListen("composer:open", () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useListen("composer:close", () => {
|
||||||
|
open.value = false;
|
||||||
|
});
|
||||||
|
|
||||||
const open = ref(false);
|
const open = ref(false);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,6 @@ const { text } = defineProps<{
|
||||||
const { copy } = useClipboard();
|
const { copy } = useClipboard();
|
||||||
const copyText = () => {
|
const copyText = () => {
|
||||||
copy(text);
|
copy(text);
|
||||||
toast("Copied to clipboard", {
|
toast.success("Copied to clipboard");
|
||||||
icon: <Check class="size-5 text-green-500" />,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -34,17 +34,13 @@ const { copy } = useClipboard();
|
||||||
|
|
||||||
const copyText = (text: string) => {
|
const copyText = (text: string) => {
|
||||||
copy(text);
|
copy(text);
|
||||||
toast("Copied to clipboard", {
|
toast.success("Copied to clipboard");
|
||||||
icon: <Check class="size-5 text-green-500" />,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const blockUser = async (id: string) => {
|
const blockUser = async (id: string) => {
|
||||||
await client.value.blockAccount(id);
|
await client.value.blockAccount(id);
|
||||||
|
|
||||||
toast("User blocked", {
|
toast.success("User blocked");
|
||||||
icon: <Ban class="size-5 text-destructive" />,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
15
components/ui/select/Select.vue
Normal file
15
components/ui/select/Select.vue
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import type { SelectRootEmits, SelectRootProps } from "radix-vue";
|
||||||
|
import { SelectRoot, useForwardPropsEmits } from "radix-vue";
|
||||||
|
|
||||||
|
const props = defineProps<SelectRootProps>();
|
||||||
|
const emits = defineEmits<SelectRootEmits>();
|
||||||
|
|
||||||
|
const forwarded = useForwardPropsEmits(props, emits);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<SelectRoot v-bind="forwarded">
|
||||||
|
<slot />
|
||||||
|
</SelectRoot>
|
||||||
|
</template>
|
||||||
53
components/ui/select/SelectContent.vue
Normal file
53
components/ui/select/SelectContent.vue
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import {
|
||||||
|
SelectContent,
|
||||||
|
type SelectContentEmits,
|
||||||
|
type SelectContentProps,
|
||||||
|
SelectPortal,
|
||||||
|
SelectViewport,
|
||||||
|
useForwardPropsEmits,
|
||||||
|
} from "radix-vue";
|
||||||
|
import { type HTMLAttributes, computed } from "vue";
|
||||||
|
import { SelectScrollDownButton, SelectScrollUpButton } from ".";
|
||||||
|
|
||||||
|
defineOptions({
|
||||||
|
inheritAttrs: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<SelectContentProps & { class?: HTMLAttributes["class"] }>(),
|
||||||
|
{
|
||||||
|
position: "popper",
|
||||||
|
},
|
||||||
|
);
|
||||||
|
const emits = defineEmits<SelectContentEmits>();
|
||||||
|
|
||||||
|
const delegatedProps = computed(() => {
|
||||||
|
const { class: _, ...delegated } = props;
|
||||||
|
|
||||||
|
return delegated;
|
||||||
|
});
|
||||||
|
|
||||||
|
const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<SelectPortal>
|
||||||
|
<SelectContent
|
||||||
|
v-bind="{ ...forwarded, ...$attrs }" :class="cn(
|
||||||
|
'relative z-50 max-h-96 min-w-32 overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
|
||||||
|
position === 'popper'
|
||||||
|
&& 'data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1',
|
||||||
|
props.class,
|
||||||
|
)
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<SelectScrollUpButton />
|
||||||
|
<SelectViewport :class="cn('p-1', position === 'popper' && 'h-[--radix-select-trigger-height] w-full min-w-[--radix-select-trigger-width]')">
|
||||||
|
<slot />
|
||||||
|
</SelectViewport>
|
||||||
|
<SelectScrollDownButton />
|
||||||
|
</SelectContent>
|
||||||
|
</SelectPortal>
|
||||||
|
</template>
|
||||||
21
components/ui/select/SelectGroup.vue
Normal file
21
components/ui/select/SelectGroup.vue
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { SelectGroup, type SelectGroupProps } from "radix-vue";
|
||||||
|
import { type HTMLAttributes, computed } from "vue";
|
||||||
|
|
||||||
|
const props = defineProps<
|
||||||
|
SelectGroupProps & { class?: HTMLAttributes["class"] }
|
||||||
|
>();
|
||||||
|
|
||||||
|
const delegatedProps = computed(() => {
|
||||||
|
const { class: _, ...delegated } = props;
|
||||||
|
|
||||||
|
return delegated;
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<SelectGroup :class="cn('p-1 w-full', props.class)" v-bind="delegatedProps">
|
||||||
|
<slot />
|
||||||
|
</SelectGroup>
|
||||||
|
</template>
|
||||||
46
components/ui/select/SelectItem.vue
Normal file
46
components/ui/select/SelectItem.vue
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { Check } from "lucide-vue-next";
|
||||||
|
import {
|
||||||
|
SelectItem,
|
||||||
|
SelectItemIndicator,
|
||||||
|
type SelectItemProps,
|
||||||
|
SelectItemText,
|
||||||
|
useForwardProps,
|
||||||
|
} from "radix-vue";
|
||||||
|
import { type HTMLAttributes, computed } from "vue";
|
||||||
|
|
||||||
|
const props = defineProps<
|
||||||
|
SelectItemProps & { class?: HTMLAttributes["class"] }
|
||||||
|
>();
|
||||||
|
|
||||||
|
const delegatedProps = computed(() => {
|
||||||
|
const { class: _, ...delegated } = props;
|
||||||
|
|
||||||
|
return delegated;
|
||||||
|
});
|
||||||
|
|
||||||
|
const forwardedProps = useForwardProps(delegatedProps);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<SelectItem
|
||||||
|
v-bind="forwardedProps"
|
||||||
|
:class="
|
||||||
|
cn(
|
||||||
|
'relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-10 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
|
||||||
|
props.class,
|
||||||
|
)
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<span class="absolute left-3 flex size-3.5 items-center justify-center">
|
||||||
|
<SelectItemIndicator>
|
||||||
|
<Check class="size-4" />
|
||||||
|
</SelectItemIndicator>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<SelectItemText class="w-full">
|
||||||
|
<slot />
|
||||||
|
</SelectItemText>
|
||||||
|
</SelectItem>
|
||||||
|
</template>
|
||||||
11
components/ui/select/SelectItemText.vue
Normal file
11
components/ui/select/SelectItemText.vue
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { SelectItemText, type SelectItemTextProps } from "radix-vue";
|
||||||
|
|
||||||
|
const props = defineProps<SelectItemTextProps>();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<SelectItemText v-bind="props">
|
||||||
|
<slot />
|
||||||
|
</SelectItemText>
|
||||||
|
</template>
|
||||||
15
components/ui/select/SelectLabel.vue
Normal file
15
components/ui/select/SelectLabel.vue
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { SelectLabel, type SelectLabelProps } from "radix-vue";
|
||||||
|
import type { HTMLAttributes } from "vue";
|
||||||
|
|
||||||
|
const props = defineProps<
|
||||||
|
SelectLabelProps & { class?: HTMLAttributes["class"] }
|
||||||
|
>();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<SelectLabel :class="cn('py-1.5 pl-8 pr-2 text-sm font-semibold', props.class)">
|
||||||
|
<slot />
|
||||||
|
</SelectLabel>
|
||||||
|
</template>
|
||||||
30
components/ui/select/SelectScrollDownButton.vue
Normal file
30
components/ui/select/SelectScrollDownButton.vue
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { ChevronDown } from "lucide-vue-next";
|
||||||
|
import {
|
||||||
|
SelectScrollDownButton,
|
||||||
|
type SelectScrollDownButtonProps,
|
||||||
|
useForwardProps,
|
||||||
|
} from "radix-vue";
|
||||||
|
import { type HTMLAttributes, computed } from "vue";
|
||||||
|
|
||||||
|
const props = defineProps<
|
||||||
|
SelectScrollDownButtonProps & { class?: HTMLAttributes["class"] }
|
||||||
|
>();
|
||||||
|
|
||||||
|
const delegatedProps = computed(() => {
|
||||||
|
const { class: _, ...delegated } = props;
|
||||||
|
|
||||||
|
return delegated;
|
||||||
|
});
|
||||||
|
|
||||||
|
const forwardedProps = useForwardProps(delegatedProps);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<SelectScrollDownButton v-bind="forwardedProps" :class="cn('flex cursor-default items-center justify-center py-1', props.class)">
|
||||||
|
<slot>
|
||||||
|
<ChevronDown class="h-4 w-4" />
|
||||||
|
</slot>
|
||||||
|
</SelectScrollDownButton>
|
||||||
|
</template>
|
||||||
30
components/ui/select/SelectScrollUpButton.vue
Normal file
30
components/ui/select/SelectScrollUpButton.vue
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { ChevronUp } from "lucide-vue-next";
|
||||||
|
import {
|
||||||
|
SelectScrollUpButton,
|
||||||
|
type SelectScrollUpButtonProps,
|
||||||
|
useForwardProps,
|
||||||
|
} from "radix-vue";
|
||||||
|
import { type HTMLAttributes, computed } from "vue";
|
||||||
|
|
||||||
|
const props = defineProps<
|
||||||
|
SelectScrollUpButtonProps & { class?: HTMLAttributes["class"] }
|
||||||
|
>();
|
||||||
|
|
||||||
|
const delegatedProps = computed(() => {
|
||||||
|
const { class: _, ...delegated } = props;
|
||||||
|
|
||||||
|
return delegated;
|
||||||
|
});
|
||||||
|
|
||||||
|
const forwardedProps = useForwardProps(delegatedProps);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<SelectScrollUpButton v-bind="forwardedProps" :class="cn('flex cursor-default items-center justify-center py-1', props.class)">
|
||||||
|
<slot>
|
||||||
|
<ChevronUp class="h-4 w-4" />
|
||||||
|
</slot>
|
||||||
|
</SelectScrollUpButton>
|
||||||
|
</template>
|
||||||
19
components/ui/select/SelectSeparator.vue
Normal file
19
components/ui/select/SelectSeparator.vue
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { SelectSeparator, type SelectSeparatorProps } from "radix-vue";
|
||||||
|
import { type HTMLAttributes, computed } from "vue";
|
||||||
|
|
||||||
|
const props = defineProps<
|
||||||
|
SelectSeparatorProps & { class?: HTMLAttributes["class"] }
|
||||||
|
>();
|
||||||
|
|
||||||
|
const delegatedProps = computed(() => {
|
||||||
|
const { class: _, ...delegated } = props;
|
||||||
|
|
||||||
|
return delegated;
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<SelectSeparator v-bind="delegatedProps" :class="cn('-mx-1 my-1 h-px bg-muted', props.class)" />
|
||||||
|
</template>
|
||||||
38
components/ui/select/SelectTrigger.vue
Normal file
38
components/ui/select/SelectTrigger.vue
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { ChevronDown } from "lucide-vue-next";
|
||||||
|
import {
|
||||||
|
SelectIcon,
|
||||||
|
SelectTrigger,
|
||||||
|
type SelectTriggerProps,
|
||||||
|
useForwardProps,
|
||||||
|
} from "radix-vue";
|
||||||
|
import { type HTMLAttributes, computed } from "vue";
|
||||||
|
|
||||||
|
const props = defineProps<
|
||||||
|
SelectTriggerProps & { class?: HTMLAttributes["class"] }
|
||||||
|
>();
|
||||||
|
|
||||||
|
const delegatedProps = computed(() => {
|
||||||
|
const { class: _, ...delegated } = props;
|
||||||
|
|
||||||
|
return delegated;
|
||||||
|
});
|
||||||
|
|
||||||
|
const forwardedProps = useForwardProps(delegatedProps);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<SelectTrigger
|
||||||
|
v-bind="forwardedProps"
|
||||||
|
:class="cn(
|
||||||
|
'flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background data-[placeholder]:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:truncate text-start',
|
||||||
|
props.class,
|
||||||
|
)"
|
||||||
|
>
|
||||||
|
<slot />
|
||||||
|
<SelectIcon as-child>
|
||||||
|
<ChevronDown class="w-4 h-4 opacity-50 shrink-0" />
|
||||||
|
</SelectIcon>
|
||||||
|
</SelectTrigger>
|
||||||
|
</template>
|
||||||
11
components/ui/select/SelectValue.vue
Normal file
11
components/ui/select/SelectValue.vue
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { SelectValue, type SelectValueProps } from "radix-vue";
|
||||||
|
|
||||||
|
const props = defineProps<SelectValueProps>();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<SelectValue v-bind="props">
|
||||||
|
<slot />
|
||||||
|
</SelectValue>
|
||||||
|
</template>
|
||||||
11
components/ui/select/index.ts
Normal file
11
components/ui/select/index.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
export { default as Select } from "./Select.vue";
|
||||||
|
export { default as SelectContent } from "./SelectContent.vue";
|
||||||
|
export { default as SelectGroup } from "./SelectGroup.vue";
|
||||||
|
export { default as SelectItem } from "./SelectItem.vue";
|
||||||
|
export { default as SelectItemText } from "./SelectItemText.vue";
|
||||||
|
export { default as SelectLabel } from "./SelectLabel.vue";
|
||||||
|
export { default as SelectScrollDownButton } from "./SelectScrollDownButton.vue";
|
||||||
|
export { default as SelectScrollUpButton } from "./SelectScrollUpButton.vue";
|
||||||
|
export { default as SelectSeparator } from "./SelectSeparator.vue";
|
||||||
|
export { default as SelectTrigger } from "./SelectTrigger.vue";
|
||||||
|
export { default as SelectValue } from "./SelectValue.vue";
|
||||||
45
components/ui/toggle/Toggle.vue
Normal file
45
components/ui/toggle/Toggle.vue
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import {
|
||||||
|
Toggle,
|
||||||
|
type ToggleEmits,
|
||||||
|
type ToggleProps,
|
||||||
|
useForwardPropsEmits,
|
||||||
|
} from "radix-vue";
|
||||||
|
import { type HTMLAttributes, computed } from "vue";
|
||||||
|
import { type ToggleVariants, toggleVariants } from ".";
|
||||||
|
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<
|
||||||
|
ToggleProps & {
|
||||||
|
class?: HTMLAttributes["class"];
|
||||||
|
variant?: ToggleVariants["variant"];
|
||||||
|
size?: ToggleVariants["size"];
|
||||||
|
}
|
||||||
|
>(),
|
||||||
|
{
|
||||||
|
variant: "default",
|
||||||
|
size: "default",
|
||||||
|
disabled: false,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
const emits = defineEmits<ToggleEmits>();
|
||||||
|
|
||||||
|
const delegatedProps = computed(() => {
|
||||||
|
const { class: _, size, variant, ...delegated } = props;
|
||||||
|
|
||||||
|
return delegated;
|
||||||
|
});
|
||||||
|
|
||||||
|
const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Toggle
|
||||||
|
v-bind="forwarded"
|
||||||
|
:class="cn(toggleVariants({ variant, size }), props.class)"
|
||||||
|
>
|
||||||
|
<slot />
|
||||||
|
</Toggle>
|
||||||
|
</template>
|
||||||
27
components/ui/toggle/index.ts
Normal file
27
components/ui/toggle/index.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
import { type VariantProps, cva } from "class-variance-authority";
|
||||||
|
|
||||||
|
export { default as Toggle } from "./Toggle.vue";
|
||||||
|
|
||||||
|
export const toggleVariants = cva(
|
||||||
|
"inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground",
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
variant: {
|
||||||
|
default: "bg-transparent",
|
||||||
|
outline:
|
||||||
|
"border border-input bg-transparent hover:bg-accent hover:text-accent-foreground",
|
||||||
|
},
|
||||||
|
size: {
|
||||||
|
default: "h-10 px-3",
|
||||||
|
sm: "h-9 px-2.5",
|
||||||
|
lg: "h-11 px-5",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
variant: "default",
|
||||||
|
size: "default",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export type ToggleVariants = VariantProps<typeof toggleVariants>;
|
||||||
Loading…
Reference in a new issue