Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
fix: relation widget style fixes (#911)
Browse files Browse the repository at this point in the history
  • Loading branch information
KaneFreeman authored Oct 4, 2023
1 parent 2d2b048 commit a0bc731
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 47 deletions.
23 changes: 15 additions & 8 deletions packages/core/src/components/common/autocomplete/Autocomplete.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
.CMS_Autocomplete_root {
@apply relative
w-full;
w-full
flex
items-center
gap-2
pr-2;

&.CMS_Autocomplete_disabled {
& .CMS_Autocomplete_input {
Expand All @@ -15,13 +19,19 @@
}
}

.CMS_Autocomplete_input-wrapper {
@apply flex-grow
flex
flex-wrap
min-w-0;
}

.CMS_Autocomplete_input {
@apply w-full
bg-transparent
border-none
py-2
pl-3
pr-10
text-sm
leading-5
focus:ring-0
Expand All @@ -33,13 +43,10 @@
}

.CMS_Autocomplete_button-wrapper {
@apply absolute
inset-y-0
right-0
flex
@apply flex
items-center
pr-2
gap-1;
gap-1
flex-shrink-0;
}

.CMS_Autocomplete_button {
Expand Down
22 changes: 14 additions & 8 deletions packages/core/src/components/common/autocomplete/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const classes = generateClassNames('Autocomplete', [
'root',
'focused',
'disabled',
'input-wrapper',
'input',
'button-wrapper',
'button',
Expand Down Expand Up @@ -55,6 +56,7 @@ export interface AutocompleteProps {
disabled?: boolean;
required?: boolean;
inputRef?: Ref<HTMLInputElement>;
endAdornment?: ReactNode;
displayValue: (item: string | string[] | null) => string;
onQuery: (query: string) => void;
onChange: (value: string | string[] | undefined) => void;
Expand All @@ -64,9 +66,10 @@ const Autocomplete = ({
label,
value,
options,
inputRef,
disabled,
required,
inputRef,
endAdornment,
onChange,
onQuery,
}: AutocompleteProps) => {
Expand Down Expand Up @@ -187,14 +190,17 @@ const Autocomplete = ({
)}
data-testid="autocomplete"
>
{label}
<input
{...getInputProps()}
ref={finalInputRef}
className={classes.input}
data-testid="autocomplete-input"
/>
<div className={classes['input-wrapper']}>
{label}
<input
{...getInputProps()}
ref={finalInputRef}
className={classes.input}
data-testid="autocomplete-input"
/>
</div>
<div className={classes['button-wrapper']}>
{endAdornment}
<IconButton
variant="text"
size="small"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.CMS_CircularProgress_svg {
@apply mr-2
text-gray-200
@apply text-gray-200
animate-spin
dark:text-gray-600
fill-blue-600;
Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -427,3 +427,12 @@ table {
height: 24px;
}
}

::-moz-focus-inner,
:focus-visible {
@apply outline-none;
}

.MuiPopper-root {
@apply z-[100];
}
10 changes: 4 additions & 6 deletions packages/core/src/widgets/relation/RelationControl.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
gap-2
p-2
pr-0
w-relation-widget-label;
min-w-0;
}

.CMS_WidgetRelation_loading {
@apply absolute
inset-y-0
right-4
flex
@apply flex
items-center
pr-2;
w-6
h-6;
}
44 changes: 22 additions & 22 deletions packages/core/src/widgets/relation/RelationControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -358,28 +358,18 @@ const RelationControl: FC<WidgetControlProps<string | string[], RelationField>>
>
<Autocomplete
label={
<>
{Array.isArray(selectedValue) && selectedValue.length > 0 ? (
<div className={classes.values}>
{selectedValue.map(selectValue => {
const option = uniqueOptionsByValue[selectValue];
return (
<Pill key={selectValue} noWrap disabled={disabled}>
{option?.label ?? selectValue}
</Pill>
);
})}
</div>
) : null}
{loading ? (
<CircularProgress
key="loading-indicator"
className={classes.loading}
data-testid="relation-loading-indicator"
size="small"
/>
) : null}
</>
Array.isArray(selectedValue) && selectedValue.length > 0 ? (
<div className={classes.values}>
{selectedValue.map(selectValue => {
const option = uniqueOptionsByValue[selectValue];
return (
<Pill key={selectValue} noWrap disabled={disabled}>
{option?.label ?? selectValue}
</Pill>
);
})}
</div>
) : null
}
inputRef={ref}
value={selectedValue}
Expand All @@ -398,6 +388,16 @@ const RelationControl: FC<WidgetControlProps<string | string[], RelationField>>

return option.label;
}}
endAdornment={
loading ? (
<CircularProgress
key="loading-indicator"
className={classes.loading}
data-testid="relation-loading-indicator"
size="small"
/>
) : null
}
onQuery={filterOptions}
onChange={handleChange}
/>
Expand Down
1 change: 0 additions & 1 deletion tailwind.base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ module.exports = {
"breadcrumb-title": "calc(100vw * .4)",
"collection-header": "calc(100% - 32px)",
"date-widget": "calc(100% - 58px)",
"relation-widget-label": "calc(100% - 32px)",
"select-widget-label": "calc(100% - 12px)",
},
maxWidth: {
Expand Down

0 comments on commit a0bc731

Please sign in to comment.