Skip to content

Commit

Permalink
Add small refactoring changes
Browse files Browse the repository at this point in the history
  • Loading branch information
david0xd committed Sep 6, 2024
1 parent a400da7 commit d484154
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
5 changes: 5 additions & 0 deletions packages/snaps-sdk/src/jsx/validation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ describe('FieldStruct', () => {
<Text>Hello</Text>
</Box>
</Field>,
<Field label="foo">
<Text>Hello</Text>
<Input name="foo" type="text" />
<Text>Hello</Text>
</Field>,
<Field label="foo">
<Input name="foo" type="text" />
<Button>foo</Button>
Expand Down
44 changes: 22 additions & 22 deletions packages/snaps-sdk/src/jsx/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,28 +285,6 @@ export const FileInputStruct: Describe<FileInputElement> = element(
},
);

export const BoxChildrenStruct = children(
// eslint-disable-next-line @typescript-eslint/no-use-before-define
[lazy(() => BoxChildStruct)],
) as unknown as Struct<SnapsChildren<GenericSnapElement>, null>;

/**
* A struct for the {@link BoxElement} type.
*/
export const BoxStruct: Describe<BoxElement> = element('Box', {
children: BoxChildrenStruct,
direction: optional(nullUnion([literal('horizontal'), literal('vertical')])),
alignment: optional(
nullUnion([
literal('start'),
literal('center'),
literal('end'),
literal('space-between'),
literal('space-around'),
]),
),
});

/**
* A subset of JSX elements that represent the tuple Box + Input of the Field children.
*/
Expand Down Expand Up @@ -449,6 +427,28 @@ export const AddressStruct: Describe<AddressElement> = element('Address', {
address: nullUnion([HexChecksumAddressStruct, CaipAccountIdStruct]),
});

export const BoxChildrenStruct = children(
// eslint-disable-next-line @typescript-eslint/no-use-before-define
[lazy(() => BoxChildStruct)],
) as unknown as Struct<SnapsChildren<GenericSnapElement>, null>;

/**
* A struct for the {@link BoxElement} type.
*/
export const BoxStruct: Describe<BoxElement> = element('Box', {
children: BoxChildrenStruct,
direction: optional(nullUnion([literal('horizontal'), literal('vertical')])),
alignment: optional(
nullUnion([
literal('start'),
literal('center'),
literal('end'),
literal('space-between'),
literal('space-around'),
]),
),
});

const FooterButtonStruct = refine(ButtonStruct, 'FooterButton', (value) => {
if (
typeof value.props.children === 'string' ||
Expand Down

0 comments on commit d484154

Please sign in to comment.