-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
87 changed files
with
235 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,17 @@ | ||
<script lang="ts"> | ||
import { asComponentHref } from '$docs/utilities.js'; | ||
import { Button, Heading, Icon, VStack } from '@immich/ui'; | ||
type Props = { | ||
title: string; | ||
icon: string; | ||
component: { name: string; icon: string }; | ||
}; | ||
const { title, icon }: Props = $props(); | ||
const asSlug = (value: string) => | ||
value.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`).replace(/^-/, ''); | ||
const { component }: Props = $props(); | ||
</script> | ||
|
||
<Button href="/examples/{asSlug(title)}" variant="outline" color="primary" class="h-24 w-40"> | ||
<Button href={asComponentHref(component.name)} variant="outline" color="primary" class="h-24 w-40"> | ||
<VStack gap={2} class="p-6"> | ||
<Icon {icon} size="2em" /> | ||
<Heading size="tiny">{title}</Heading> | ||
<Icon icon={component.icon} size="2em" /> | ||
<Heading size="tiny">{component.name}</Heading> | ||
</VStack> | ||
</Button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const asSlug = (value: string) => | ||
value.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`).replace(/^-/, ''); | ||
|
||
export const asComponentHref = (componentName: string) => `/components/${asSlug(componentName)}`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<script lang="ts"> | ||
import { getBytesWithUnit } from '$lib/utilities/byte-units.js'; | ||
type Props = { | ||
bytes: number; | ||
precision?: number; | ||
variant?: 'short' | 'narrow'; | ||
}; | ||
const { bytes, precision, variant = 'short' }: Props = $props(); | ||
const [value, unit] = $derived(getBytesWithUnit(bytes, precision)); | ||
const separator = $derived(variant === 'narrow' ? '' : ' '); | ||
</script> | ||
|
||
<span>{value}{separator}{unit}</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
export const enum ByteUnit { | ||
'B' = 'B', | ||
'KiB' = 'KiB', | ||
'MiB' = 'MiB', | ||
'GiB' = 'GiB', | ||
'TiB' = 'TiB', | ||
'PiB' = 'PiB', | ||
'EiB' = 'EiB', | ||
} | ||
|
||
const byteUnits = [ | ||
ByteUnit.B, | ||
ByteUnit.KiB, | ||
ByteUnit.MiB, | ||
ByteUnit.GiB, | ||
ByteUnit.TiB, | ||
ByteUnit.PiB, | ||
ByteUnit.EiB, | ||
]; | ||
|
||
/** | ||
* Convert bytes to best human readable unit and number of that unit. | ||
* | ||
* * For `1024` bytes, returns `1` and `KiB`. | ||
* * For `1536` bytes, returns `1.5` and `KiB`. | ||
* | ||
* @param bytes number of bytes | ||
* @param maxPrecision maximum number of decimal places, default is `1` | ||
* @returns size (number) and unit (string) | ||
*/ | ||
export function getBytesWithUnit(bytes: number, maxPrecision = 1): [number, ByteUnit] { | ||
const magnitude = Math.floor(Math.log(bytes === 0 ? 1 : bytes) / Math.log(1024)); | ||
|
||
return [ | ||
Number.parseFloat((bytes / 1024 ** magnitude).toFixed(maxPrecision)), | ||
byteUnits[magnitude], | ||
]; | ||
} | ||
|
||
/** | ||
* Localized number of bytes with a unit. | ||
* | ||
* For `1536` bytes: | ||
* * en: `1.5 KiB` | ||
* * de: `1,5 KiB` | ||
* | ||
* @param bytes number of bytes | ||
* @param maxPrecision maximum number of decimal places, default is `1` | ||
* @returns localized bytes with unit as string | ||
*/ | ||
export function getByteUnitString(bytes: number, locale?: string, maxPrecision = 1): string { | ||
const [size, unit] = getBytesWithUnit(bytes, maxPrecision); | ||
return `${size.toLocaleString(locale)} ${unit}`; | ||
} | ||
|
||
/** | ||
* Convert to bytes from on a specified unit. | ||
* | ||
* * `1, 'GiB'`, returns `1073741824` bytes | ||
* | ||
* @param size value to be converted | ||
* @param unit unit to convert from | ||
* @returns bytes (number) | ||
*/ | ||
export function convertToBytes(size: number, unit: ByteUnit): number { | ||
return size * 1024 ** byteUnits.indexOf(unit); | ||
} | ||
|
||
/** | ||
* Convert from bytes to a specified unit. | ||
* | ||
* * `11073741824, 'GiB'`, returns `1` GiB | ||
* | ||
* @param bytes value to be converted | ||
* @param unit unit to convert to | ||
* @returns bytes (number) | ||
*/ | ||
export function convertFromBytes(bytes: number, unit: ByteUnit): number { | ||
return bytes / 1024 ** byteUnits.indexOf(unit); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions
3
...es/examples/app-shell/BasicExample.svelte → .../components/app-shell/BasicExample.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 9 additions & 2 deletions
11
src/routes/examples/card/BasicExample.svelte → ...outes/components/card/BasicExample.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.