-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[IndexFilters] Loading spinner moved to be a suffix within the search box. #10808
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@shopify/polaris': patch | ||
--- | ||
|
||
[IndexFilters] Loading spinner moved to be a suffix within the search box. | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
@import '../../../../styles/common'; | ||
|
||
.SearchField { | ||
// stylelint-disable-next-line -- Polaris component custom properties | ||
--pc-indexfilter-search-padding-inline: var(--p-space-150); | ||
position: relative; | ||
display: flex; | ||
padding-block: var(--p-space-025); | ||
|
@@ -19,7 +21,8 @@ | |
border: var(--p-border-width-025) solid var(--p-color-input-border); | ||
border-radius: var(--p-border-radius-100); | ||
border-color: var(--p-color-input-border); | ||
padding-inline: var(--p-space-150); | ||
// stylelint-disable-next-line -- Polaris component custom properties | ||
padding-inline: var(--pc-indexfilter-search-padding-inline); | ||
width: 100%; | ||
|
||
&:hover { | ||
|
@@ -54,19 +57,32 @@ | |
outline-offset: var(--p-space-025); | ||
} | ||
|
||
.ClearButton { | ||
.Suffix { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ |
||
position: absolute; | ||
top: 50%; | ||
right: 0; | ||
// stylelint-disable-next-line -- Polaris component custom properties | ||
right: var(--pc-indexfilter-search-padding-inline); | ||
transform: translateY(-50%); | ||
} | ||
|
||
.ClearButton { | ||
background: none; | ||
border: none; | ||
transform: translateY(-50%); | ||
opacity: 0; | ||
transition: opacity var(--p-motion-duration-150) var(--p-motion-ease-in-out); | ||
cursor: pointer; | ||
padding: 0; | ||
} | ||
|
||
.ClearButton-focused { | ||
opacity: 1; | ||
pointer-events: auto; | ||
} | ||
|
||
.Spinner { | ||
width: var(--p-space-500); | ||
|
||
svg { | ||
display: block; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,6 +1,8 @@ | ||||||
import React, {useEffect, useRef, useId} from 'react'; | ||||||
import {CircleCancelMinor} from '@shopify/polaris-icons'; | ||||||
|
||||||
import {InlineStack} from '../../../InlineStack'; | ||||||
import {Spinner} from '../../../Spinner'; | ||||||
import {Text} from '../../../Text'; | ||||||
import {classNames} from '../../../../utilities/css'; | ||||||
import {Icon} from '../../../Icon'; | ||||||
|
@@ -19,6 +21,8 @@ export interface SearchFieldProps { | |||||
placeholder?: string; | ||||||
disabled?: boolean; | ||||||
borderlessQueryField?: boolean; | ||||||
/** Show a loading spinner to the right of the input */ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
loading?: boolean; | ||||||
} | ||||||
|
||||||
export function SearchField({ | ||||||
|
@@ -31,6 +35,7 @@ export function SearchField({ | |||||
placeholder, | ||||||
disabled, | ||||||
borderlessQueryField, | ||||||
loading, | ||||||
}: SearchFieldProps) { | ||||||
const i18n = useI18n(); | ||||||
const id = useId(); | ||||||
|
@@ -72,21 +77,32 @@ export function SearchField({ | |||||
placeholder={placeholder} | ||||||
disabled={disabled} | ||||||
/> | ||||||
{value !== '' && ( | ||||||
<UnstyledButton | ||||||
className={classNames( | ||||||
styles.ClearButton, | ||||||
focused && styles['ClearButton-focused'], | ||||||
)} | ||||||
onClick={() => handleClear()} | ||||||
disabled={disabled} | ||||||
> | ||||||
<Text as="span" visuallyHidden> | ||||||
{i18n.translate('Polaris.Common.clear')} | ||||||
</Text> | ||||||
<Icon source={CircleCancelMinor} tone="subdued" /> | ||||||
</UnstyledButton> | ||||||
)} | ||||||
{loading || value !== '' ? ( | ||||||
<div className={styles.Suffix}> | ||||||
<InlineStack gap="200"> | ||||||
{loading ? ( | ||||||
<div className={styles.Spinner}> | ||||||
<Spinner size="small" /> | ||||||
</div> | ||||||
) : null} | ||||||
{value !== '' ? ( | ||||||
<UnstyledButton | ||||||
className={classNames( | ||||||
styles.ClearButton, | ||||||
focused && styles['ClearButton-focused'], | ||||||
)} | ||||||
onClick={() => handleClear()} | ||||||
disabled={disabled} | ||||||
> | ||||||
<Text as="span" visuallyHidden> | ||||||
{i18n.translate('Polaris.Common.clear')} | ||||||
</Text> | ||||||
<Icon source={CircleCancelMinor} tone="subdued" /> | ||||||
</UnstyledButton> | ||||||
) : null} | ||||||
</InlineStack> | ||||||
</div> | ||||||
Comment on lines
+80
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's move the markup for each of the suffix items into variables so there aren't conditionals in the return. const loadingMarkup = loading
? (
<div className={styles.Spinner}>
<Spinner size="small" />
</div>
) : null;
const clearButtonMarkup = value !== ''
? (
<UnstyledButton
onClick={() => handleClear()}
disabled={disabled}
className={classNames(
styles.ClearButton,
focused && styles['ClearButton-focused'],
)}
>
<Text as="span" visuallyHidden>
{i18n.translate('Polaris.Common.clear')}
</Text>
<Icon source={CircleCancelMinor} tone="subdued" />
</UnstyledButton>
) : null
const suffixMarkup = loading || value !== ''
? (
<div className={styles.Suffix}>
<InlineStack gap="200">
{loadingMarkup}
{clearButtonMarkup}
</InlineStack>
</div>
) : null;
....
....
{suffixMarkup} |
||||||
) : null} | ||||||
</div> | ||||||
); | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.