Skip to content

Commit

Permalink
Prevent color-like strings from changing the Text component to a Colo…
Browse files Browse the repository at this point in the history
…r component . Addresses #17 .
  • Loading branch information
kitschpatrol committed Sep 19, 2024
1 parent 2af2471 commit 244967f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
1 change: 0 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ module.exports = {
'@typescript-eslint/no-duplicate-type-constituents': 'off',
'@typescript-eslint/no-redundant-type-constituents': 'off',
'@typescript-eslint/no-unnecessary-type-arguments': 'off',

'@typescript-eslint/restrict-plus-operands': 'off',
'no-return-assign': 'off',
'unicorn/no-null': 'off',
Expand Down
50 changes: 50 additions & 0 deletions src/examples/tests/TestTextStringDetection.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<script lang="ts">
// Svelte Tweakpane UI's Text component should NOT give color-like string
// special treatment, use the Color component instead.
//
// Related:
// https://github.com/kitschpatrol/svelte-tweakpane-ui/issues/17
import { Text } from '$lib';
let sample01 = 'Hi';
let sample02 = '1';
let sample03 = '0x13';
let sample04 = '0x1337';
let sample05 = '0xEE1337';
let sample06 = '0x1337AA';
let sample07 = '0x1337AA13';
let sample08 = '#13';
let sample09 = '#1337';
let sample10 = '#EE1337';
let sample11 = '#1337AA';
let sample12 = '#1337AA13';
let sample13 = '238, 19, 55';
let sample14 = '238, 19, 55, 0.5';
let sample15 = 'rgb(238, 19, 55)';
let sample16 = 'rgba(238, 19, 55, 0.5)';
let sample17 = 'True';
let sample18 = 'true';
let sample19 = 'False';
let sample20 = 'false';
</script>

<Text bind:value={sample01} />
<Text bind:value={sample02} />
<Text bind:value={sample03} />
<Text bind:value={sample04} />
<Text bind:value={sample05} />
<Text bind:value={sample06} />
<Text bind:value={sample07} />
<Text bind:value={sample08} />
<Text bind:value={sample09} />
<Text bind:value={sample10} />
<Text bind:value={sample11} />
<Text bind:value={sample12} />
<Text bind:value={sample13} />
<Text bind:value={sample14} />
<Text bind:value={sample15} />
<Text bind:value={sample16} />
<Text bind:value={sample17} />
<Text bind:value={sample18} />
<Text bind:value={sample19} />
<Text bind:value={sample20} />
6 changes: 5 additions & 1 deletion src/lib/control/Text.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
change: TextChangeEvent;
};
// Do not allow for automatic detection of hex / color strings
// See https://github.com/kitschpatrol/svelte-tweakpane-ui/issues/17
const options = { view: 'text' };
// Tweakpane's implementation only sends updates on blur we extend it to send continues change
// updates if desired
let ref: GenericInputRef;
Expand Down Expand Up @@ -98,4 +102,4 @@ position="inline">`.
[Text.svelte](https://github.com/kitschpatrol/svelte-tweakpane-ui/blob/main/src/lib/control/Text.svelte)
-->

<GenericInput bind:value bind:ref on:change {...$$restProps} />
<GenericInput bind:value bind:ref on:change {options} {...$$restProps} />

0 comments on commit 244967f

Please sign in to comment.