Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: SSRI Demo #152

Merged
merged 4 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"dependencies": {
"@lit/react": "^1.0.5",
"@uiw/react-json-view": "2.0.0-alpha.30",
"lucide-react": "^0.427.0",
"next": "14.2.10",
"react": "^18",
Expand All @@ -24,6 +25,8 @@
"devDependencies": {
"@ckb-ccc/connector-react": "workspace:*",
"@ckb-ccc/lumos-patches": "workspace:*",
"@ckb-ccc/ssri": "workspace:*",
"@ckb-ccc/udt": "workspace:*",
"@ckb-lumos/ckb-indexer": "^0.24.0-next.1",
"@ckb-lumos/common-scripts": "^0.24.0-next.1",
"@ckb-lumos/config-manager": "^0.24.0-next.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
"use client";

import { TextInput } from "@/src/components/Input";
import { Button } from "@/src/components/Button";


interface HexInputProps {
value: string;
onChange: (value: string) => void;
onRemove?: () => void;
label?: string;
placeholder?: string;
}

interface HexArrayInputProps {
value: string[];
onChange: (value: string[]) => void;
label?: string;
}

export const HexInput: React.FC<HexInputProps> = ({
value,
label = "Hex Value",
placeholder = "Enter hex value (with 0x prefix)",
onChange,
onRemove,
}) => {
return (
<div className="flex w-full flex-col gap-2 rounded border p-2">
<TextInput
label={label}
placeholder={placeholder}
state={[
value,
(newValue) => {
// Ensure hex format
const hexValue = newValue.startsWith("0x")
? newValue
: `0x${newValue}`;
onChange(hexValue);
},
]}
className="w-full"
/>
{onRemove && (
<Button
onClick={onRemove}
className="self-start rounded bg-red-500 px-2 py-1 text-white"
>
Remove
</Button>
)}
</div>
);
};

export const HexArrayInput: React.FC<HexArrayInputProps> = ({
value = [],
onChange,
label = "Hex Values",
}) => {
const addHexValue = () => {
onChange([...value, "0x"]);
};

const removeHexValue = (index: number) => {
const newValues = [...value];
newValues.splice(index, 1);
onChange(newValues);
};

const updateHexValue = (index: number, hexValue: string) => {
const newValues = [...value];
newValues[index] = hexValue;
onChange(newValues);
};

return (
<div className="flex flex-col gap-2">
<label className="font-semibold">{label}</label>
{value.map((hexValue, index) => (
<HexInput
key={index}
value={hexValue}
label={`Hex Value ${index + 1}`}
placeholder={`Enter hex value (with 0x prefix)`}
onChange={(updatedValue) => updateHexValue(index, updatedValue)}
onRemove={() => removeHexValue(index)}
/>
))}
<Button
onClick={addHexValue}
className="self-start rounded bg-green-500 px-2 py-1 text-white"
>
Add Hex Value
</Button>
</div>
);
};
Loading