Skip to content

Commit

Permalink
feat(ui-components): new API method initTheme to override default F…
Browse files Browse the repository at this point in the history
…luent UI styles, removing `-webkit-font-smoothing: antialiased`. (#2478)

* feat: init theme to avoid font smoothing

init theme to avoid font smoothing

* test: additional test

additional test

* fix: execute from storybook

execute from storybook

* comment

comment

* test: coverage

coverage
  • Loading branch information
815are authored Oct 18, 2024
1 parent 550e708 commit ea18bcb
Show file tree
Hide file tree
Showing 26 changed files with 60 additions and 77 deletions.
5 changes: 5 additions & 0 deletions .changeset/gorgeous-melons-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sap-ux/ui-components': minor
---

Added new API method `initTheme` to override default Fluent UI styles, removing `-webkit-font-smoothing: antialiased`.
5 changes: 5 additions & 0 deletions packages/ui-components/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { initTheme } from '../src/theme';
import { initIcons } from '../src/components/Icons';

initTheme();
initIcons();
1 change: 1 addition & 0 deletions packages/ui-components/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './components';
export * from './utilities';
export * from './theme';
15 changes: 15 additions & 0 deletions packages/ui-components/src/theme/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { Theme } from '@fluentui/react';
import { createTheme, loadTheme } from '@fluentui/react';

/**
* Method intializes default styles for 'ui-components' theme.
*/
export function initTheme(): void {
const appTheme: Theme = createTheme({
defaultFontStyle: {
WebkitFontSmoothing: ''
}
});

loadTheme(appTheme);
}
4 changes: 1 addition & 3 deletions packages/ui-components/stories/UICallout.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import React, { useState } from 'react';
import { UIDefaultButton, UIIconButton } from '../src/components/UIButton';
import { UICallout, UICalloutContentPadding } from '../src/components/UICallout';
import { UIFocusZone } from '../src/components/UIFocusZone';
import { initIcons, UiIcons } from '../src/components/Icons';

initIcons();
import { UiIcons } from '../src/components/Icons';

export default { title: 'Dropdowns/Callout' };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@ import {
UITextInput,
UICallout,
UICheckbox,
initIcons,
CalloutCollisionTransform
} from '../src/components';
import { data } from '../test/__mock__/select-data';

initIcons();

export default { title: 'Dialogs/Dialogs' };

enum ControlTypes {
Expand Down
4 changes: 0 additions & 4 deletions packages/ui-components/stories/UICheckbox.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import { Text, Stack } from '@fluentui/react';

import { UICheckbox } from '../src/components/UICheckbox';

import { initIcons } from '../src/components/Icons';

initIcons();

export default { title: 'Basic Inputs/Checkbox' };
const stackTokens: IStackTokens = { childrenGap: 40 };

Expand Down
4 changes: 0 additions & 4 deletions packages/ui-components/stories/UIChoiceGroup.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import { Text, Stack } from '@fluentui/react';
import type { ChoiceGroupOption } from '../src/components/UIChoiceGroup';
import { UIChoiceGroup } from '../src/components/UIChoiceGroup';

import { initIcons } from '../src/components/Icons';

initIcons();

export default { title: 'Basic Inputs/ChoiceGroup' };

const props: any = {
Expand Down
3 changes: 0 additions & 3 deletions packages/ui-components/stories/UICombobox.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ import {
import { UICheckbox } from '../src/components/UICheckbox';
import { data, groupsData } from '../test/__mock__/select-data';

import { initIcons } from '../src/components/Icons';
import { UITextInput } from '../src/components';

initIcons();

export default { title: 'Dropdowns/Combobox' };

export const SearchHighlight = (): JSX.Element => (
Expand Down
4 changes: 1 addition & 3 deletions packages/ui-components/stories/UIContextualMenu.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ import {
} from '../src/components/UIContextualMenu';
import { UIDefaultButton, UIIconButton } from '../src/components/UIButton';
import { UIDirectionalHint } from '../src/components/UITreeDropdown';
import { initIcons, UiIcons } from '../src/components/Icons';
import { UiIcons } from '../src/components/Icons';
import { UIDropdown } from '../src/components/UIDropdown';
import { UIToggle } from '../src/components/UIToggle';

initIcons();

export default { title: 'Dropdowns/ContextualMenu' };
const stackTokens: IStackTokens = { childrenGap: 40 };
function getItems(iconsToLeft = false): UIContextualMenuItem[] {
Expand Down
3 changes: 0 additions & 3 deletions packages/ui-components/stories/UICreateSelect.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import {
UICreateSelectInstance
} from '../src/components/UICreateSelect';
import { UILabel } from '../src/components/UILabel';
import { initIcons } from '../src/components/Icons';

initIcons();

export default { title: 'Dropdowns/CreateSelect' };
const stackTokens: IStackTokens = { childrenGap: 40 };
Expand Down
4 changes: 0 additions & 4 deletions packages/ui-components/stories/UIDatePicker.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import { Text, Stack } from '@fluentui/react';

import { UIDatePicker } from '../src/components/UIDatePicker';

import { initIcons } from '../src/components/Icons';

initIcons();

export default { title: 'Basic Inputs/DatePicker' };
const stackTokens: IStackTokens = { childrenGap: 40 };

Expand Down
4 changes: 0 additions & 4 deletions packages/ui-components/stories/UIDialog.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import { UIDropdown } from '../src/components/UIDropdown';
import { UIComboBox } from '../src/components/UIComboBox';
import { UICheckbox } from '../src/components/UICheckbox';

import { initIcons } from '../src/components/Icons';

initIcons();

export default { title: 'Dialogs/Dialogs' };

const stackTokens: IStackTokens = { childrenGap: 40 };
Expand Down
3 changes: 0 additions & 3 deletions packages/ui-components/stories/UIDropdown.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ import {
UISelectableOptionMenuItemType,
UICheckbox,
UIDropdown,
initIcons,
UISelectableOption,
UITextInput
} from '../src/components';
import { data, shortData, groupsData } from '../test/__mock__/select-data';

initIcons();

export default { title: 'Dropdowns/Dropdown' };

export const Basic = (): JSX.Element => (
Expand Down
4 changes: 0 additions & 4 deletions packages/ui-components/stories/UIFlexibleTable.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ import {

import { arrayMove } from 'react-movable';

import { initIcons } from '../src/components/Icons';

initIcons();

export default { title: 'Tables/UIFlexibleTable' };
const tableIds = ['table1', 'table2'];

Expand Down
3 changes: 0 additions & 3 deletions packages/ui-components/stories/UIIcon.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ import React from 'react';
import type { IColumn } from '@fluentui/react';
import { DetailsList, SelectionMode } from '@fluentui/react';
import { UIIcon } from '../src/components/UIIcon';
import { initIcons, UiIcons } from '../src/components/Icons';

export default { title: 'Utilities/Icons' };

initIcons();

const items: any = [];
for (const icon in UiIcons) {
items.push(icon);
Expand Down
3 changes: 0 additions & 3 deletions packages/ui-components/stories/UILabel.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import React from 'react';
import type { IStackTokens } from '@fluentui/react';
import { Text, Stack } from '@fluentui/react';
import { UILabel } from '../src/components/UILabel';
import { initIcons } from '../src/components/Icons';

initIcons();

export default { title: 'Basic Inputs/Label' };
const stackTokens: IStackTokens = { childrenGap: 40 };
Expand Down
2 changes: 0 additions & 2 deletions packages/ui-components/stories/UILoader.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ import type { IStackTokens } from '@fluentui/react';
import { Text, Stack, SpinnerSize } from '@fluentui/react';

import { UILoader } from '../src/components/UILoader';
import { initIcons } from '../src/components/Icons';
import { UIDefaultButton } from '../src/components/UIButton';
import { UIDialog } from '../src/components/UIDialog';

export default { title: 'Progress/Loader' };

initIcons();
const stackTokens: IStackTokens = { childrenGap: 40 };

export const Loaders = () => (
Expand Down
18 changes: 10 additions & 8 deletions packages/ui-components/stories/UIQuickNavigation.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ import React from 'react';
import {
UIQuickNavigation,
UIDefaultButton,
initIcons,
UITextInput,
setQuickNavigationKey,
UIQuickNavigationOffset
} from '../src/components';

export default { title: 'Utilities/Quick Navigation' };

initIcons();

const value = {
name: 'Hello, world!',
html: '<span><strong>Tag:</strong> name</span>'
Expand Down Expand Up @@ -67,9 +64,14 @@ export const External = () => {
};

export const ExternalWithCustomOffset = () => {
return <QuickNavigation inline={false} offsets={[
{ y: 30, x: 0},
{ y: 0, x: 30},
{ y: -15, x: -15}
]} />;
return (
<QuickNavigation
inline={false}
offsets={[
{ y: 30, x: 0 },
{ y: 0, x: 30 },
{ y: -15, x: -15 }
]}
/>
);
};
3 changes: 0 additions & 3 deletions packages/ui-components/stories/UISearchBox.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ import type { ISearchBoxProps, IStackTokens } from '@fluentui/react';
import { Text, Stack } from '@fluentui/react';

import { UISearchBox } from '../src/components/UISearchBox';
import { initIcons } from '../src/components/Icons';
import { UICheckbox } from '../src/components';

export default { title: 'Basic Inputs/Search' };
const stackTokens: IStackTokens = { childrenGap: 40 };

initIcons();

export const SearchBox = () => {
const [query, setQuery] = useState('');

Expand Down
3 changes: 0 additions & 3 deletions packages/ui-components/stories/UITextInput.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ import { Text, Stack, Separator } from '@fluentui/react';

import { UITextInput } from '../src/components/UIInput';
import { UICheckbox } from '../src/components/UICheckbox';
import { initIcons } from '../src/components/Icons';

export default { title: 'Basic Inputs/Input' };

initIcons();

const stackTokens: IStackTokens = { childrenGap: 40 };
const iconFolderProps = { iconName: 'FolderOpened' };

Expand Down
3 changes: 0 additions & 3 deletions packages/ui-components/stories/UIToggleGroup.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import React, { useState } from 'react';
import type { IStackTokens } from '@fluentui/react';
import { Text, Stack } from '@fluentui/react';
import { UIToggleGroup } from '../src/components/UIToggleGroup';
import { initIcons } from '../src/components/Icons';

initIcons();

export default { title: 'Basic Inputs/Toggle/Group' };
const stackTokens: IStackTokens = { childrenGap: 40 };
Expand Down
3 changes: 0 additions & 3 deletions packages/ui-components/stories/UITooltip.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ import React from 'react';

import { UITooltip, UITooltipUtils } from '../src/components/UITooltip';
import { UIDefaultButton } from '../src/components/UIButton';
import { initIcons } from '../src/components/Icons';

export default { title: 'Dropdowns/Tooltip' };

initIcons();

const value = {
name: 'Hello, world!',
html: '<span><strong>Tag:</strong> name</span>'
Expand Down
4 changes: 1 addition & 3 deletions packages/ui-components/stories/UITranslationInput.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { IStackTokens } from '@fluentui/react';
import { Stack } from '@fluentui/react';
import type { I18nBundle, TranslationEntry } from '../src/components/UITranslationInput';
import { TranslationTextPattern, UITranslationInput } from '../src/components/UITranslationInput';
import { initIcons, UiIcons } from '../src/components/Icons';
import { UiIcons } from '../src/components/Icons';
import { UITable } from '../src/components/UITable';
import type { UIColumn } from '../src/components/UITable';
import { UIIconButton } from '../src/components/UIButton';
Expand All @@ -26,8 +26,6 @@ interface CustomTranslationEntry extends TranslationEntry {
dummyPath: string;
}

initIcons();

const stackTokens: IStackTokens = { childrenGap: 60 };

const I18N_BUNDLE_KEY = 'ui-components-i18n-bundle';
Expand Down
15 changes: 7 additions & 8 deletions packages/ui-components/stories/Utilities.story.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React, { useState } from 'react';
import { Stack } from '@fluentui/react';
import type { IStackTokens } from '@fluentui/react';
import { initIcons, UICallout } from '../src/components';

initIcons();
import { UICallout } from '../src/components';

export default { title: 'Utilities/Misc' };

Expand All @@ -15,11 +13,12 @@ const getContent = (name: string): JSX.Element => {
style={{
padding: 10
}}>
{name}<br />
lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua ut enim ad minim veniam quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat
nulla pariatur excepteur sint occaecat cupidatat non proident sunt in culpa qui officia deserunt
{name}
<br />
lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore
magna aliqua ut enim ad minim veniam quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
pariatur excepteur sint occaecat cupidatat non proident sunt in culpa qui officia deserunt
</div>
);
};
Expand Down
14 changes: 14 additions & 0 deletions packages/ui-components/test/unit/theme/Theme.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { initTheme } from '../../../src';
import * as fluentUI from '@fluentui/react';

describe('initTheme', () => {
it('initTheme', () => {
const createThemeSpy = jest.spyOn(fluentUI, 'createTheme');
initTheme();
expect(createThemeSpy).toBeCalledWith({
defaultFontStyle: {
WebkitFontSmoothing: ''
}
});
});
});

0 comments on commit ea18bcb

Please sign in to comment.