Skip to content

Commit

Permalink
fix(Currency): added class identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
N00nDay committed Oct 4, 2023
1 parent e744409 commit f39df32
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
33 changes: 26 additions & 7 deletions src/lib/components/currency/Currency.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import Icon from '../icon';
import { error as errorIcon, close } from '../../icons';
import { writable, type Writable } from 'svelte/store';
import { twMerge } from 'tailwind-merge';
export let name: string;
export let error: string | undefined = undefined;
Expand Down Expand Up @@ -42,11 +43,17 @@
value = undefined;
}
const finalClass = twMerge(
'stwui-currency-wrapper',
$$props.class
);
setContext('currency-name', name);
setContext('currency-error', currentError);
</script>

<div class={$$props.class} style={$$props.style}>
<div class={finalClass} style={$$props.style}>
<slot name="label" />
<div
class="mt-1 relative rounded-md h-[2.5rem]"
Expand All @@ -64,7 +71,7 @@
{readonly}
{disabled}
id={name}
class="block w-full px-3 h-[2.5rem] border outline-none focus:outline-none sm:text-sm rounded-md bg-surface placeholder-secondary-content placeholder-opacity-80"
class="block w-full px-3 h-[2.5rem] border outline-none focus:outline-none sm:text-sm rounded-md bg-surface placeholder-secondary-content placeholder-opacity-80 stwui-currency-input"
class:border-danger={error}
class:text-danger={error}
class:placeholder-danger={error}
Expand All @@ -82,7 +89,9 @@
/>

{#if $$slots.leading}
<span class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
<span
class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none stwui-currency-leading-wrapper"
>
<slot name="leading" />
</span>
{/if}
Expand All @@ -91,7 +100,7 @@
<button
aria-label="clear"
on:click={handleClear}
class="absolute inset-y-0 group-focus-within:flex active:flex items-center"
class="absolute inset-y-0 group-focus-within:flex active:flex items-center stwui-currency-clear-wrapper"
class:right-10={$$slots.trailing || error}
class:right-3={!$$slots.trailing && !error}
>
Expand All @@ -102,17 +111,27 @@
{/if}

{#if $$slots.trailing && !error}
<span class="absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none">
<span
class="absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none stwui-currency-trailing-wrapper"
>
<slot name="trailing" />
</span>
{:else if error}
<span class="absolute inset-y-0 right-0 flex items-center pr-2 pointer-events-none">
<span
class="absolute inset-y-0 right-0 flex items-center pr-2 pointer-events-none stwui-currency-error-icon"
>
<Icon data={errorIcon} />
</span>
{/if}
</div>
{#if error}
<p transition:slide|local class="mt-2 text-sm text-danger" id="{name}-error">{error}</p>
<p
transition:slide|local
class="mt-2 text-sm text-danger stwui-currency-error"
id="{name}-error"
>
{error}
</p>
{/if}
</div>

Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/currency/Label.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
const name: string = getContext('currency-name');
const error: Writable<string | undefined> = getContext('currency-error');
const defaultClass = 'block text-sm font-medium text-secondary-content';
const defaultClass = 'block text-sm font-medium text-secondary-content stwui-currency-label';
const errorClass = 'text-danger';
$: finalClass = twMerge(
Expand Down

0 comments on commit f39df32

Please sign in to comment.