Skip to content
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
1 change: 1 addition & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Enhancements

- Added `showFocusBorder` prop to the `TopBar.SearchField` to allow users to add show a border on focus ([#2886](https://github.com/Shopify/polaris-react/pull/2886)).
- Added a theme prop for `frameOffset` ([#2887](https://github.com/Shopify/polaris-react/pull/2887))

### Bug fixes
Expand Down
2 changes: 2 additions & 0 deletions src/components/ThemeProvider/tests/ThemeProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ describe('<ThemeProvider />', () => {
'--top-bar-background': '#108043',
'--top-bar-background-lighter': 'hsla(147, 63%, 43%, 1)',
'--top-bar-color': 'rgb(255, 255, 255)',
'--top-bar-border': 'rgb(196, 205, 213)',
}),
});
});
Expand Down Expand Up @@ -127,6 +128,7 @@ describe('<ThemeProvider />', () => {
'--top-bar-background': '#021123',
'--top-bar-background-lighter': 'hsla(213, 74%, 22%, 1)',
'--top-bar-color': 'rgb(255, 255, 255)',
'--top-bar-border': 'rgb(196, 205, 213)',
}),
});
});
Expand Down
1 change: 1 addition & 0 deletions src/components/TopBar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ function TopBarExample() {
onChange={handleSearchChange}
value={searchValue}
placeholder="Search"
showFocusBorder
/>
);

Expand Down
8 changes: 8 additions & 0 deletions src/components/TopBar/components/SearchField/SearchField.scss
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ $stacking-order: (
background-color: var(--p-action-secondary, color('white'));
}

~ .BackdropShowFocusBorder {
border: 1px solid var(--top-bar-border, transparent);
}

~ .Icon {
@include recolor-icon(var(--p-icon-subdued, color('ink', 'lightest')));
}
Expand All @@ -69,6 +73,10 @@ $stacking-order: (
background-color: var(--p-action-secondary, color('white'));
}

.BackdropShowFocusBorder {
border: 1px solid var(--top-bar-border, transparent);
}

.Icon {
@include recolor-icon(var(--p-icon-subdued, color('ink', 'lightest')));
}
Expand Down
10 changes: 9 additions & 1 deletion src/components/TopBar/components/SearchField/SearchField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export interface SearchFieldProps {
onBlur?(): void;
/** Callback when search field cancel button is clicked */
onCancel?(): void;
/** Show a border when the search field is focused */
showFocusBorder?: boolean;
}

export function SearchField({
Expand All @@ -38,6 +40,7 @@ export function SearchField({
onFocus,
onBlur,
onCancel,
showFocusBorder,
}: SearchFieldProps) {
const i18n = useI18n();
const [forceActive, setForceActive] = useState(false);
Expand Down Expand Up @@ -131,7 +134,12 @@ export function SearchField({
</span>

{clearMarkup}
<div className={styles.Backdrop} />
<div
className={classNames(
styles.Backdrop,
showFocusBorder && styles.BackdropShowFocusBorder,
)}
/>
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ describe('<TextField />', () => {
});
});

it('adds a "BackdropShowFocusBorder" class when "showFocusBorder" is passed', () => {
const textField = mountWithAppProvider(
<SearchField value="" onChange={noop} showFocusBorder />,
);

expect(textField.find('div').last().prop('className')).toBe(
'Backdrop BackdropShowFocusBorder',
);
});

describe('newDesignLanguage', () => {
it('does not render a container with newDesignLanguage className by default', () => {
const textField = mountWithApp(
Expand Down
1 change: 1 addition & 0 deletions src/utilities/custom-properties/custom-properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const nonDesignLangaugeCustomProperties = [
'--Polaris-RangeSlider-output-factor',
'--top-bar-color',
'--top-bar-background-lighter',
'--top-bar-border',
'--p-frame-offset',
];

Expand Down
25 changes: 25 additions & 0 deletions src/utilities/theme/tests/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {needsVariantList} from '../config';
import {
needsVariant,
setTextColor,
setBorderColor,
setTheme,
buildThemeContext,
buildCustomProperties,
Expand All @@ -18,12 +19,34 @@ describe('setTextColor', () => {
expect(textColor).toStrictEqual(['topBar', tokens.colorWhite]);
});

it('sets a css variable to white if the variant has no value', () => {
const textColor = setTextColor('topBar');
expect(textColor).toStrictEqual(['topBar', tokens.colorWhite]);
});

it('sets a css variable to ink if the variant is light', () => {
const textColor = setTextColor('topBar', 'light');
expect(textColor).toStrictEqual(['topBar', tokens.colorInk]);
});
});

describe('setBorderColor', () => {
it('sets a css variable to sky dark if the variant is dark', () => {
const textColor = setBorderColor('topBar', 'dark');
expect(textColor).toStrictEqual(['topBar', tokens.colorSkyDark]);
});

it('sets a css variable to sky dark if the variant has no value', () => {
const textColor = setBorderColor('topBar');
expect(textColor).toStrictEqual(['topBar', tokens.colorSkyDark]);
});

it('sets a css variable to ink lighter if the variant is light', () => {
const textColor = setBorderColor('topBar', 'light');
expect(textColor).toStrictEqual(['topBar', tokens.colorInkLighter]);
});
});

describe('setTheme', () => {
it('returns a base theme', () => {
const theme = setTheme(
Expand All @@ -35,6 +58,7 @@ describe('setTheme', () => {

expect(theme).toStrictEqual([
['--top-bar-color', 'rgb(255, 255, 255)'],
['--top-bar-border', 'rgb(196, 205, 213)'],
['--top-bar-background-lighter', 'hsla(184, 85%, 43%, 1)'],
]);
});
Expand All @@ -57,6 +81,7 @@ describe('buildCustomProperties', () => {
'--p-frame-offset': '0px',
'--top-bar-background': '#eeeeee',
'--top-bar-background-lighter': 'hsla(0, 10%, 100%, 1)',
'--top-bar-border': 'rgb(99, 115, 129)',
'--top-bar-color': 'rgb(33, 43, 54)',
};

Expand Down
18 changes: 18 additions & 0 deletions src/utilities/theme/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ export function setTextColor(
return [name, tokens.colorWhite];
}

export function setBorderColor(
name: string,
variant: 'light' | 'dark' = 'dark',
): string[] {
if (variant === 'light') {
return [name, tokens.colorInkLighter];
}
return [name, tokens.colorSkyDark];
}

export function setTheme(
color: string | HSLColor,
baseName: string,
Expand All @@ -135,6 +145,10 @@ export function setTheme(
setTextColor(constructColorName(baseName, null, 'color'), 'light'),
);

colorPairs.push(
setBorderColor(constructColorName(baseName, null, 'border'), 'light'),
);

colorPairs.push([
constructColorName(baseName, key, 'lighter'),
lightenToString(color, 7, -10),
Expand All @@ -146,6 +160,10 @@ export function setTheme(
setTextColor(constructColorName(baseName, null, 'color'), 'dark'),
);

colorPairs.push(
setBorderColor(constructColorName(baseName, null, 'border'), 'dark'),
);

colorPairs.push([
constructColorName(baseName, key, 'lighter'),
lightenToString(color, 15, 15),
Expand Down