Skip to content

Commit

Permalink
Add string utils to top-level exports and add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
techniq committed Nov 13, 2023
1 parent fa6b3c1 commit c046b08
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/rotten-meals-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte-ux': patch
---

Add string utils to top-level exports and add docs
3 changes: 1 addition & 2 deletions packages/svelte-ux/src/lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export { round, clamp } from './number';
export * from './promise';
export * from './sort';
export { cls } from './styles';
export { uniqueId } from './string';
export * from './string';

// aliased exports to remove conflicts (and make imports less noisy from top-level)
export * as array from './array';
Expand All @@ -25,6 +25,5 @@ export * as object from './object';
export * as rollup from './rollup';
export * as routing from './routing';
export * as serialize from './serialize';
export * as string from './string';
export * as styles from './styles';
export * as table from './table';
2 changes: 1 addition & 1 deletion packages/svelte-ux/src/routes/_NavMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
'uniqueStore',
];
const utils = ['cls', 'format', 'json', 'Logger'];
const utils = ['cls', 'format', 'json', 'Logger', 'string'];
</script>

<NavItem text="Getting Started" icon={mdiHome} currentUrl={$page.url} path="/" />
Expand Down
55 changes: 55 additions & 0 deletions packages/svelte-ux/src/routes/docs/utils/string/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<script lang="ts">
import Preview from '$lib/components/Preview.svelte';
import { uniqueId, truncate, toTitleCase } from '$lib/utils/string';
import Code from '$lib/components/Code.svelte';
import RangeField from '$lib/components/RangeField.svelte';
let str = 'This is very long text that will be truncated';
let totalChars = 20;
let endChars = 5;
</script>

<h1>Usage</h1>

<Code
source={`import { uniqueId, truncate, toTitleCase } from 'svelte-ux';`}
language="javascript"
class="mb-4"
/>

<h1>Examples</h1>

<h2>truncate()</h2>

<Code source={`import { truncate } from 'svelte-ux';`} language="javascript" class="mb-4" />

<h3>Playground</h3>
<div class="grid grid-cols-2 gap-2 mb-2">
<RangeField label="Total chars" bind:value={totalChars} />
<RangeField label="End chars" bind:value={endChars} />
</div>
<Preview>
<div>{truncate(str, totalChars, endChars)}</div>
</Preview>

<h3>Total only</h3>
<Preview>
<div>{truncate(str, 20)}</div>
</Preview>

<h3>Middle ellipsis</h3>
<Preview>
<div>{truncate(str, 20, 10)}</div>
</Preview>

<h2>unique()</h2>

<Code source={`import { uniqueId } from 'svelte-ux';`} language="javascript" class="mb-4" />

<h3>Basic</h3>
<Preview>
<div>{uniqueId('checkbox-')}</div>
<div>{uniqueId('checkbox-')}</div>
<div>{uniqueId('checkbox-')}</div>
<div>{uniqueId('radio-')}</div>
</Preview>
12 changes: 12 additions & 0 deletions packages/svelte-ux/src/routes/docs/utils/string/+page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import source from '$lib/utils/string.ts?raw';
import pageSource from './+page.svelte?raw';

export async function load() {
return {
meta: {
source,
pageSource,
description: 'String utilities',
},
};
}

1 comment on commit c046b08

@vercel
Copy link

@vercel vercel bot commented on c046b08 Nov 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.