update select label + added global functions for String type

main
TZGyn 1 year ago
parent f2f8c6871b
commit 0b0f5cee37
Signed by: TZGyn
GPG Key ID: 122EAF77AE81FD4A

@ -109,6 +109,10 @@ declare global {
} }
} }
} }
interface String {
removeUnderscores(): string
capitalize(): string
}
} }
export {} export {}

@ -1,16 +1,16 @@
<script lang="ts"> <script lang="ts">
import Check from "lucide-svelte/icons/check"; import Check from 'lucide-svelte/icons/check'
import { Select as SelectPrimitive } from "bits-ui"; import { Select as SelectPrimitive } from 'bits-ui'
import { cn } from "$lib/utils.js"; import { cn } from '$lib/utils.js'
type $$Props = SelectPrimitive.ItemProps; type $$Props = SelectPrimitive.ItemProps
type $$Events = SelectPrimitive.ItemEvents; type $$Events = SelectPrimitive.ItemEvents
let className: $$Props["class"] = undefined; let className: $$Props['class'] = undefined
export let value: $$Props["value"]; export let value: $$Props['value']
export let label: $$Props["label"] = undefined; export let label: $$Props['label'] = undefined
export let disabled: $$Props["disabled"] = undefined; export let disabled: $$Props['disabled'] = undefined
export { className as class }; export { className as class }
</script> </script>
<SelectPrimitive.Item <SelectPrimitive.Item
@ -18,8 +18,8 @@
{disabled} {disabled}
{label} {label}
class={cn( class={cn(
"relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none data-[disabled]:pointer-events-none data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground data-[disabled]:opacity-50", 'relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none data-[disabled]:pointer-events-none data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground data-[disabled]:opacity-50',
className className,
)} )}
{...$$restProps} {...$$restProps}
on:click on:click
@ -27,14 +27,12 @@
on:focusin on:focusin
on:focusout on:focusout
on:pointerleave on:pointerleave
on:pointermove on:pointermove>
> <span
<span class="absolute left-2 flex h-3.5 w-3.5 items-center justify-center"> class="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
<SelectPrimitive.ItemIndicator> <SelectPrimitive.ItemIndicator>
<Check class="h-4 w-4" /> <Check class="h-4 w-4" />
</SelectPrimitive.ItemIndicator> </SelectPrimitive.ItemIndicator>
</span> </span>
<slot> <slot />
{label || value}
</slot>
</SelectPrimitive.Item> </SelectPrimitive.Item>

@ -69,3 +69,12 @@ export const flyAndScale = (
easing: cubicOut, easing: cubicOut,
} }
} }
// this works because its imported in the root layout by other components
String.prototype.removeUnderscores = function () {
return this.replace(/_/g, ' ')
}
String.prototype.capitalize = function () {
return this.charAt(0).toUpperCase() + this.slice(1)
}

Loading…
Cancel
Save