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

Cb 3773 form controls #2023

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
aaba27d
feat: migrate InputFiles to css modules
teunlao Sep 25, 2023
654e1bf
feat: migrate InputFiles to css modules
teunlao Sep 25, 2023
ffb40be
feat: migrate Radio to css modules
teunlao Sep 25, 2023
3eee099
feat: migrate Textarea to css modules
teunlao Sep 25, 2023
68941e6
feat: migrate Filter to css modules
teunlao Sep 25, 2023
fffff59
feat: migrate InputFileTextContent to css modules
teunlao Sep 25, 2023
9c63c5c
feat: migrate FormBox and FormBoxElement to css modules
teunlao Sep 25, 2023
47770a4
feat: migrate FormGroup to css modules
teunlao Sep 25, 2023
13e38b1
fix: fixes after review
teunlao Sep 27, 2023
9170a7b
fix: remove old styles from Filter
teunlao Sep 27, 2023
37ed2ee
fix: remove old styles from InputField
teunlao Sep 27, 2023
69f6359
fix: remove old styles from Textarea
teunlao Sep 27, 2023
5826b82
Merge remote-tracking branch 'origin/devel' into CB-3773-form-controls
teunlao Sep 27, 2023
4582f7c
fix: refactor with field components
teunlao Sep 27, 2023
c5b13da
fix: fixes after review
teunlao Sep 28, 2023
46ca56b
Merge branch 'devel' into CB-3773-form-controls
Wroud Sep 28, 2023
77359aa
Merge branch 'devel' into CB-3773-form-controls
mr-anton-t Sep 28, 2023
6be7ffc
Merge remote-tracking branch 'origin/devel' into CB-3773-form-controls
teunlao Sep 28, 2023
c93909e
fix: remove mod prop from UseFormInfoCredentials
teunlao Sep 28, 2023
910376d
fix: users table filter styles
teunlao Oct 2, 2023
7b4236a
Merge remote-tracking branch 'origin/devel' into CB-3773-form-controls
teunlao Oct 2, 2023
123b785
fix: users table filter styles
teunlao Oct 2, 2023
75a6462
Merge branch 'devel' into CB-3773-form-controls
mr-anton-t Oct 3, 2023
943b9d5
Merge branch 'devel' into CB-3773-form-controls
mr-anton-t Oct 3, 2023
d04c829
Merge branch 'devel' into CB-3773-form-controls
mr-anton-t Oct 3, 2023
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
49 changes: 49 additions & 0 deletions webapp/packages/core-blocks/src/FormControls/Filter.m.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.filterContainer {
position: relative;
min-width: 24px;
min-height: 24px;
}
.inputField {
display: none;
width: 300px;
&.max {
width: 100%;
}
&.toggled {
display: block;
}

& input {
padding-right: 40px !important;
}

}
.iconButton {
position: absolute;
right: 0;
top: 0;
margin: 0;
width: 24px;
height: 24px;
border-radius: 2px;
cursor: auto;

&.toggled {
right: 4px;
top: 4px;
}
&.cross {
width: 16px;
height: 16px;
top: 8px;
right: 8px;
}
}

.innerInputStyle {
}

.toggleMode {
composes: theme-background-primary theme-text-on-primary from global;
cursor: pointer;
}
78 changes: 15 additions & 63 deletions webapp/packages/core-blocks/src/FormControls/Filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,67 +7,16 @@
*/
import { observer } from 'mobx-react-lite';
import { useCallback, useEffect, useState } from 'react';
import styled, { css, use } from 'reshadow';

import type { ComponentStyle } from '@cloudbeaver/core-theming';

import { IconButton } from '../IconButton';
import { s } from '../s';
import { useFocus } from '../useFocus';
import { useStyles } from '../useStyles';
import { useS } from '../useS';
import filterStyle from './Filter.m.css';
import { InputField } from './InputField';

const filterStyles = css`
filter-container {
position: relative;
min-width: 24px;
min-height: 24px;
}
InputField {
display: none;
width: 300px;
&[|max] {
width: 100%;
}
&[|toggled] {
display: block;
}
}
IconButton {
position: absolute;
right: 0;
top: 0;
margin: 0;
width: 24px;
height: 24px;
border-radius: 2px;
cursor: auto;

&[|toggled] {
right: 4px;
top: 4px;
}
&[name='cross'] {
width: 16px;
height: 16px;
top: 8px;
right: 8px;
}
}
`;

const toggleModeButtonStyle = css`
IconButton {
composes: theme-background-primary theme-text-on-primary from global;
cursor: pointer;
}
`;

const innerInputStyle = css`
input {
padding-right: 40px !important;
}
`;

interface BaseProps {
toggleMode?: boolean;
placeholder?: string;
Expand Down Expand Up @@ -103,13 +52,12 @@ export const Filter = observer<ControlledProps | ObjectsProps<any, any>>(functio
disabled,
max,
className,
style,
onFilter,
onToggle,
onKeyDown,
onClick,
}) {
const styles = useStyles(filterStyles, style, toggleMode && toggleModeButtonStyle);
const styles = useS(filterStyle);
const [inputRef, ref] = useFocus<HTMLInputElement>({});
const [toggled, setToggled] = useState(!toggleMode);

Expand Down Expand Up @@ -156,24 +104,28 @@ export const Filter = observer<ControlledProps | ObjectsProps<any, any>>(functio
value = state[name];
}

return styled(styles)(
<filter-container className={className} onClick={onClick}>
return (
<div className={s(styles, { filterContainer: true })} onClick={onClick}>
<InputField
className={s(styles, { inputField: true, max, toggled }, className)}
ref={inputRef}
style={[innerInputStyle, style]}
placeholder={placeholder}
disabled={disabled}
name={name}
value={value}
onChange={filter}
onKeyDown={onKeyDown}
{...use({ toggled, max })}
/>
{String(value) ? (
<IconButton name="cross" disabled={disabled} onClick={() => filter('', name)} />
<IconButton
className={s(styles, { iconButton: true, cross: true, toggleMode })}
name="cross"
disabled={disabled}
onClick={() => filter('', name)}
/>
) : (
<IconButton name="search" disabled={disabled} onClick={toggle} {...use({ toggled })} />
<IconButton className={s(styles, { iconButton: true, toggled, toggleMode })} name="search" disabled={disabled} onClick={toggle} />
)}
</filter-container>,
</div>
);
});
24 changes: 0 additions & 24 deletions webapp/packages/core-blocks/src/FormControls/FormBox.tsx

This file was deleted.

32 changes: 0 additions & 32 deletions webapp/packages/core-blocks/src/FormControls/FormBoxElement.tsx

This file was deleted.

11 changes: 4 additions & 7 deletions webapp/packages/core-blocks/src/FormControls/FormControl.m.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,14 @@

.fieldDescription {
composes: theme-typography--caption from global;
color: var(--theme-text-hint-on-background);
box-sizing: border-box;
padding-top: 4px;
min-height: 24px;
}

.valid {
composes: theme-text-text-hint-on-light from global;
}

.invalid {
composes: theme-text-negative from global;
&.invalid {
color: var(--theme-negative);
}
}

.input,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.fieldLabel {
composes: theme-typography--body1 from global;
font-weight: 500;
margin-bottom: 10px;
box-sizing: border-box;
overflow: hidden;
white-space: initial;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
.fieldDescription {
padding: 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,31 @@
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import styled, { css } from 'reshadow';
import { observer } from 'mobx-react-lite';

import { filterLayoutFakeProps, getLayoutProps } from '../Containers/filterLayoutFakeProps';
import type { ILayoutSizeProps } from '../Containers/ILayoutSizeProps';
import elementsSizeStyles from '../Containers/shared/ElementsSize.m.css';
import { s } from '../s';
import { useS } from '../useS';
import { useStyles } from '../useStyles';
import { baseFormControlStyles, baseValidFormControlStyles } from './baseFormControlStyles';

const style = css`
field-label {
composes: theme-typography--body1 from global;
font-weight: 500;
margin-bottom: 10px;
box-sizing: border-box;
overflow: hidden;
white-space: initial;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
}
field-description {
padding: 0;
}
`;
import formControlStyles from './FormControl.m.css';
import style from './FormFieldDescription.m.css';

interface Props extends ILayoutSizeProps {
label?: string;
title?: string;
className?: string;
}

export const FormFieldDescription: React.FC<React.PropsWithChildren<Props>> = function FormFieldDescription({
label,
title,
children,
className,
...rest
}) {
export const FormFieldDescription: React.FC<React.PropsWithChildren<Props>> = observer(function FormFieldDescription({ label, title, children, className, ...rest }) {
const styles = useS(formControlStyles, elementsSizeStyles, style);
const layoutProps = getLayoutProps(rest);
rest = filterLayoutFakeProps(rest);
const styles = useStyles(baseFormControlStyles, baseValidFormControlStyles, style);
const sizeStyles = useS(elementsSizeStyles);

return styled(styles)(
<field title={title} className={s(sizeStyles, { ...layoutProps }, className)} {...rest}>
{label && <field-label as="label">{label}</field-label>}
<field-description>{children}</field-description>
</field>,
return (
<div title={title} className={s(styles, { ...layoutProps, field: true }, className)} {...rest}>
{label && <label className={s(styles, { fieldLabel: true })}>{label}</label>}
<div className={s(styles, { fieldDescription: true })}>{children}</div>
</div>
);
};
});
23 changes: 0 additions & 23 deletions webapp/packages/core-blocks/src/FormControls/FormGroup.tsx

This file was deleted.

8 changes: 3 additions & 5 deletions webapp/packages/core-blocks/src/FormControls/InputField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
import { observer } from 'mobx-react-lite';
import React, { forwardRef, useCallback, useContext, useLayoutEffect, useRef, useState } from 'react';
import styled, { use } from 'reshadow';

import type { ComponentStyle } from '@cloudbeaver/core-theming';
import { isNotNullDefined } from '@cloudbeaver/core-utils';
Expand Down Expand Up @@ -163,7 +162,7 @@ export const InputField: InputFieldType = observer(
return null;
}

return styled(propStyles)(
return (
<div data-testid="field" className={s(styles, { ...layoutProps, field: true }, className)}>
<div data-testid="field-label" title={labelTooltip || rest.title} className={styles.fieldLabel}>
{children}
Expand All @@ -180,7 +179,6 @@ export const InputField: InputFieldType = observer(
onChange={handleChange}
onBlur={handleBlur}
onKeyDown={handleKeyDown}
{...use({ mod })}
required={required}
/>
{loading && (
Expand All @@ -201,11 +199,11 @@ export const InputField: InputFieldType = observer(
{icon && <div data-testid="icon-container" className={styles.customIconContainer}>{icon}</div>}
</div>
{(description || passwordType) && (
<div data-testid="field-description" className={s(styles, { fieldDescription: true, valid: !error, invalid: error })}>
<div data-testid="field-description" className={s(styles, { fieldDescription: true, invalid: error })}>
{description}
</div>
)}
</div>,
</div>
);
}),
);
Loading
Loading