Skip to content

fix(snaps): Ensure that adjacent form elements take up to 50% width #29436

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

Merged
merged 3 commits into from
Jan 8, 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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { FunctionComponent, useEffect, useState } from 'react';
import classnames from 'classnames';
import { useSnapInterfaceContext } from '../../../../contexts/snaps';
import {
BorderColor,
Expand Down Expand Up @@ -51,7 +52,9 @@ export const SnapUICheckbox: FunctionComponent<SnapUICheckboxProps> = ({

return (
<Box
className="snap-ui-renderer__checkbox"
className={classnames('snap-ui-renderer__checkbox', {
'snap-ui-renderer__field': label !== undefined,
})}
display={Display.Flex}
flexDirection={FlexDirection.Column}
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { FunctionComponent, useEffect, useState } from 'react';
import classnames from 'classnames';
import { useSnapInterfaceContext } from '../../../../contexts/snaps';
import {
Display,
Expand Down Expand Up @@ -46,7 +47,9 @@ export const SnapUIDropdown: FunctionComponent<SnapUIDropdownProps> = ({

return (
<Box
className="snap-ui-renderer__dropdown"
className={classnames('snap-ui-renderer__dropdown', {
'snap-ui-renderer__field': label !== undefined,
})}
display={Display.Flex}
flexDirection={FlexDirection.Column}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,13 @@ export const SnapUIFileInput: FunctionComponent<SnapUIFileInputProps> = ({

if (compact) {
return (
<Box className="snap-ui-renderer__file-input">
<Box
className={classnames('snap-ui-renderer__file-input', {
'snap-ui-renderer__field': label !== undefined,
})}
display={Display.Flex}
flexDirection={FlexDirection.Column}
>
{header}
<ButtonIcon
type="button"
Expand All @@ -168,7 +174,13 @@ export const SnapUIFileInput: FunctionComponent<SnapUIFileInputProps> = ({
}

return (
<Box className="snap-ui-renderer__file-input">
<Box
className={classnames('snap-ui-renderer__file-input', {
'snap-ui-renderer__field': label !== undefined,
})}
display={Display.Flex}
flexDirection={FlexDirection.Column}
>
{header}
<Box
className="snap-ui-renderer__file-input__drop-zone"
Expand Down
9 changes: 7 additions & 2 deletions ui/components/app/snaps/snap-ui-input/snap-ui-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ import React, {
useRef,
useState,
} from 'react';
import classnames from 'classnames';
import { useSnapInterfaceContext } from '../../../../contexts/snaps';
import { FormTextField, FormTextFieldProps } from '../../../component-library';

export type SnapUIInputProps = {
name: string;
form?: string;
label?: string | React.ReactNode;
};

export const SnapUIInput: FunctionComponent<
SnapUIInputProps & FormTextFieldProps<'div'>
> = ({ name, form, ...props }) => {
> = ({ name, form, label, ...props }) => {
const { handleInputChange, getValue, focusedInput, setCurrentFocusedInput } =
useSnapInterfaceContext();

Expand Down Expand Up @@ -54,10 +56,13 @@ export const SnapUIInput: FunctionComponent<
ref={inputRef}
onFocus={handleFocus}
onBlur={handleBlur}
className="snap-ui-renderer__input"
className={classnames('snap-ui-renderer__input', {
'snap-ui-renderer__field': label !== undefined,
})}
id={name}
value={value}
onChange={handleChange}
label={label}
{...props}
/>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { FunctionComponent, useEffect, useState } from 'react';
import classnames from 'classnames';
import { useSnapInterfaceContext } from '../../../../contexts/snaps';
import {
AlignItems,
Expand Down Expand Up @@ -75,7 +76,9 @@ export const SnapUIRadioGroup: FunctionComponent<SnapUIRadioGroupProps> = ({

return (
<Box
className="snap-ui-renderer__radio"
className={classnames('snap-ui-renderer__radio', {
'snap-ui-renderer__field': label !== undefined,
})}
display={Display.Flex}
flexDirection={FlexDirection.Column}
>
Expand Down
8 changes: 8 additions & 0 deletions ui/components/app/snaps/snap-ui-renderer/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,12 @@
max-width: $width-screen-lg-min;
}
}

&__form {
.snap-ui-renderer__panel {
.snap-ui-renderer__field {
flex: 1 1 50%; // Ensure that adjacent form elements take up to 50% width
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, {
useEffect,
MouseEvent as ReactMouseEvent,
} from 'react';
import classnames from 'classnames';
import {
Box,
ButtonBase,
Expand Down Expand Up @@ -128,7 +129,13 @@ export const SnapUISelector: React.FunctionComponent<SnapUISelectorProps> = ({

return (
<>
<Box display={Display.Flex} flexDirection={FlexDirection.Column}>
<Box
display={Display.Flex}
flexDirection={FlexDirection.Column}
className={classnames({
'snap-ui-renderer__field': label !== undefined,
})}
>
{label && <Label htmlFor={name}>{label}</Label>}
<ButtonBase
className="snap-ui-renderer__selector"
Expand Down
Loading