Skip to content

Commit

Permalink
fix: fixed styles for transperant and toggler oneof (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
NasgulNexus authored Jun 7, 2023
1 parent b7a584d commit 64ca12a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/lib/kit/components/Inputs/OneOf/OneOf.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const OneOfComponent: React.FC<OneOfProps> = (props) => {
flat: props.withoutIndent,
})}
>
<div>{toggler}</div>
{toggler}
{specProperties[oneOfValue] ? (
<GroupIndent>
<Controller
Expand Down
4 changes: 4 additions & 0 deletions src/lib/kit/components/Layouts/Transparent/Transparent.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

&_without-max-width {
max-width: unset;

& > .df-error-wrapper {
width: unset;
}
}

&__remove-button {
Expand Down
1 change: 1 addition & 0 deletions src/lib/kit/hooks/useOneOf/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './useOneOf';
12 changes: 12 additions & 0 deletions src/lib/kit/hooks/useOneOf/useOneOf.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@import '../../styles/variables.scss';

.#{$ns}use-oneof {
&__toggler {
&_radio {
& > .df-row {
width: unset;
max-width: unset;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import React from 'react';
import {RadioButton, Select} from '@gravity-ui/uikit';
import _ from 'lodash';

import {ObjectIndependentInputProps} from '../../core';
import {ObjectIndependentInputProps} from '../../../core';
import {block} from '../../utils';

import './useOneOf.scss';

const b = block('use-oneof');

const MAX_TAB_TITLE_LENGTH = 20;

Expand Down Expand Up @@ -63,13 +68,17 @@ export const useOneOf = ({props, onTogglerChange}: UseOneOfParams) => {
[spec.description, spec.viewSpec.order, specProperties],
);

const togglerInput = React.useMemo(() => {
if (
const selectToggler = React.useMemo(
() =>
spec.viewSpec.oneOfParams?.toggler !== 'radio' &&
(spec.viewSpec.oneOfParams?.toggler === 'select' ||
options.length > 3 ||
_.some(options, ({title}) => title.length > MAX_TAB_TITLE_LENGTH))
) {
_.some(options, ({title}) => title.length > MAX_TAB_TITLE_LENGTH)),
[options, spec.viewSpec.oneOfParams?.toggler],
);

const togglerInput = React.useMemo(() => {
if (selectToggler) {
return (
<Select
width="max"
Expand Down Expand Up @@ -97,15 +106,23 @@ export const useOneOf = ({props, onTogglerChange}: UseOneOfParams) => {
))}
</RadioButton>
);
}, [options, oneOfValue, onOneOfChange, name, spec.viewSpec.oneOfParams?.toggler]);
}, [selectToggler, oneOfValue, spec.viewSpec.disabled, name, options, onOneOfChange]);

const toggler = React.useMemo(() => {
if (Layout) {
return <Layout {...props}>{togglerInput}</Layout>;
return (
<div
className={b('toggler', {
radio: !selectToggler,
})}
>
<Layout {...props}>{togglerInput}</Layout>
</div>
);
}

return togglerInput;
}, [Layout, togglerInput, props]);
return <div>{togglerInput}</div>;
}, [Layout, togglerInput, selectToggler, props]);

return {oneOfValue, specProperties, toggler, togglerInput};
};

0 comments on commit 64ca12a

Please sign in to comment.