feat: style checkboxes better

This commit is contained in:
2024-04-22 22:27:21 +02:00
parent 1de0094c85
commit c87d4b8dda
9 changed files with 119 additions and 40 deletions

View File

@ -11,3 +11,86 @@
</script>
<input {id} type="checkbox" bind:checked={value} />
<label for={id}>
<svg viewBox="0 0 19 14" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M2 7L7 12L17 2"
stroke="currentColor"
stroke-width="3"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
</label>
<style>
input[type="checkbox"] {
position: absolute;
overflow: hidden;
clip: rect(0 0 0 0);
height: 1px;
width: 1px;
margin: -1px;
padding: 0;
border: 0;
}
#inputPreview {
display: flex;
gap: 20px;
justify-content: center;
}
input + label {
position: relative;
font-size: 14px;
cursor: pointer;
display: inline-flex;
align-items: center;
height: 22px;
color: rgb(0, 0, 0);
}
input + label::before {
content: " ";
display: inline;
vertical-align: middle;
margin-right: 3px;
width: 22px;
height: 22px;
background-color: var(--layer-2);
border-radius: 5px;
border: none;
box-shadow: none;
}
input:checked + label::after {
content: " ";
background-repeat: no-repeat;
background-size: 12px 12px;
background-position: center center;
position: absolute;
display: flex;
justify-content: center;
align-items: center;
margin-left: 0px;
left: 0px;
top: 0px;
text-align: center;
background-color: transparent;
color: red;
font-size: 10px;
height: 22px;
width: 22px;
}
input + label > svg {
position: absolute;
display: none;
width: 12px;
height: 10px;
left: 5px;
color: var(--text-color);
top: 5.9px;
}
input:checked + label > svg {
display: block;
}
</style>

View File

@ -1,15 +1,15 @@
import { expect, test } from 'vitest'
import { decode, encode, concat_encoded } from './flatTree'
import { decodeNestedArray, encodeNestedArray, concatEncodedArrays } from './flatTree'
test("it correctly concats nested arrays", () => {
const input_a = encode([1, 2, 3]);
const input_a = encodeNestedArray([1, 2, 3]);
const input_b = 2;
const input_c = encode([4, 5, 6]);
const input_c = encodeNestedArray([4, 5, 6]);
const output = concat_encoded([input_a, input_b, input_c]);
const output = concatEncodedArrays([input_a, input_b, input_c]);
const decoded = decode(output);
const decoded = decodeNestedArray(output);
expect(decoded[0]).toEqual([1, 2, 3]);
@ -19,49 +19,49 @@ test("it correctly concats nested arrays", () => {
// Original test case
test('it correctly decodes/encodes complex nested arrays', () => {
const input = [5, [6, 1], 1, 5, [5], [7, 2, [5, 1]]];
const decoded = decode(encode(input));
const decoded = decodeNestedArray(encodeNestedArray(input));
expect(decoded).toEqual(input);
});
// Test with empty array
test('it correctly handles an empty array', () => {
const input: number[] = [];
const decoded = decode(encode(input));
const decoded = decodeNestedArray(encodeNestedArray(input));
expect(decoded).toEqual(input);
});
// Test with nested empty arrays
test('it correctly handles nested empty arrays', () => {
const input = [5, [], [6, []], []];
const decoded = decode(encode(input));
const decoded = decodeNestedArray(encodeNestedArray(input));
expect(decoded).toEqual(input);
});
// Test with single-element array
test('it correctly handles a single-element array', () => {
const input = [42];
const decoded = decode(encode(input));
const decoded = decodeNestedArray(encodeNestedArray(input));
expect(decoded).toEqual(input);
});
// Test with deeply nested array
test('it correctly handles deeply nested arrays', () => {
const input = [[[[[1]]]]];
const decoded = decode(encode(input));
const decoded = decodeNestedArray(encodeNestedArray(input));
expect(decoded).toEqual(input);
});
// Test with large numbers
test('it correctly handles large numbers', () => {
const input = [2147483647, [-2147483648, 1234567890]];
const decoded = decode(encode(input));
const decoded = decodeNestedArray(encodeNestedArray(input));
expect(decoded).toEqual(input);
});
// Test with sequential nesting
test('it correctly handles sequential nesting', () => {
const input = [1, [2, [3, [4, [5]]]]];
const decoded = decode(encode(input));
const decoded = decodeNestedArray(encodeNestedArray(input));
expect(decoded).toEqual(input);
});
@ -71,6 +71,6 @@ test('it correctly handles sequential nesting', () => {
test('it correctly handles arrays with mixed data types', () => {
const input = [1, 'text', [true, [null, ['another text']]]];
//@ts-ignore
const decoded = decode(encode(input));
const decoded = decodeNestedArray(encodeNestedArray(input));
expect(decoded).toEqual(input);
});

View File

@ -39,9 +39,6 @@ pub fn get_args(args: &[i32]) -> Vec<&[i32]> {
// skip over the bracket encoding
idx += 2;
} else {
if depth == 1 {
arg_start_index = idx + 2;
}
// skip to the next bracket if we are at depth > 0
idx = next_bracket_index;
}
@ -60,12 +57,6 @@ pub fn get_args(args: &[i32]) -> Vec<&[i32]> {
idx += 1;
}
println!("idx: {}, length: {}, asi: {}", idx, length, arg_start_index);
if arg_start_index < length {
out_args.push(&args[arg_start_index..]);
}
out_args
}
@ -111,8 +102,6 @@ pub fn wrap_arg(arg: &[i32]) -> Vec<i32> {
pub fn evaluate_node(input_args: &[i32]) -> i32 {
let node_type = input_args[0];
println!("node_type: {} -> {:?}", node_type, input_args);
match node_type {
0 => crate::nodes::math_node(&input_args[1..]),
1 => crate::nodes::random_node(&input_args[1..]),
@ -156,8 +145,6 @@ pub fn evaluate_int(input_args: &[i32]) -> i32 {
let args = get_args(input_args);
println!("args: {:?}", args);
let mut resolved: Vec<i32> = Vec::new();
for arg in args {
@ -194,7 +181,7 @@ mod tests {
// this should be the output
/* [
[ 0, 2, 1048576000, 0, 20, 0, 4, 0, 0, 1073741824, 0, 9, 0, 5, 0, 0, 1073741824, 1073741824, 1, 1, 1, 0, 1, 1, 1, 4, 1041865114 ],
[ 0, 28, 0, 2, 1048576000, 0, 20, 0, 4, 0, 0, 1073741824, 0, 9, 0, 5, 0, 0, 1073741824, 1073741824, 1, 1, 1, 0, 1, 1, 1, 4, 1041865114 ],
1086324736,
1053609165,
54
@ -204,7 +191,7 @@ mod tests {
let args = get_args(&input);
println!("{:?}", args[0]);
assert_eq!(args[0].len(), 27);
assert_eq!(args[0].len(), 29);
assert_eq!(args[1][0], 1086324736);
assert_eq!(args[2][0], 1053609165);
}
@ -230,6 +217,8 @@ mod tests {
let args = get_args(&input_a);
println!("{:?}", args);
assert_eq!(args.len(), 4);
assert_eq!(args[0], [1]);
assert_eq!(args[1], [2]);