This commit is contained in:
Andrew Coates 2024-06-04 08:47:48 -07:00
Родитель 6a67f084fc
Коммит 40526c7ade
35 изменённых файлов: 643 добавлений и 670 удалений

Просмотреть файл

@ -28,7 +28,6 @@ import { useButton } from './useButton';
* @returns Whether the styles that are assigned to the layer should be applied to the button
*/
export const buttonLookup = (layer: string, state: IPressableState, userProps: ButtonProps, theme: Theme): boolean => {
const size = userProps['size'] ?? (theme?.components?.['Button'] as ButtonTokens)?.size ?? 'medium';
const getPlatformSpecificAppearance = (theme?.components?.['Button'] as ButtonTokens)?.getPlatformSpecificAppearance;
const appearance = getPlatformSpecificAppearance ? getPlatformSpecificAppearance(userProps['appearance']) : null;

Просмотреть файл

@ -70,7 +70,7 @@ export interface ButtonCoreTokens extends LayoutTokens, FontTokens, IBorderToken
/**
* The default size of the button
*/
size?: ButtonSize,
size?: ButtonSize;
}
export interface ButtonTokens extends ButtonCoreTokens {

Просмотреть файл

@ -7,9 +7,7 @@ import type { CompoundButtonTokens, CompoundButtonSlotProps, CompoundButtonProps
import { buttonStates, contentStyling } from '../Button.styling';
export const stylingSettings: UseStylingOptions<CompoundButtonProps, CompoundButtonSlotProps, CompoundButtonTokens> = {
tokens: [
compoundButtonName,
],
tokens: [compoundButtonName],
states: buttonStates,
slotProps: {
root: buildProps(

Просмотреть файл

@ -55,4 +55,4 @@ describe('verify types', () => {
const fabColorTokens: FABTokens = defaultFABColorTokens(officeTheme);
expect(fabColorTokens).toBeTruthy();
});
})
});

Просмотреть файл

@ -1,7 +1,6 @@
import type { Theme } from '@fluentui-react-native/theme-types';
export const defaultButtonColorTokens = (t: Theme) =>
({
export const defaultButtonColorTokens = (t: Theme) => ({
/** Android does not have a different styles for 'default' button.
* 'primary', 'accent' and if no appearance is mentioned, picks this.
*/

Просмотреть файл

@ -1,8 +1,6 @@
import type { Theme } from '@fluentui-react-native/theme-types';
export const defaultButtonFontTokens = (t: Theme) =>
({
export const defaultButtonFontTokens = (t: Theme) => ({
medium: {
fontSize: t.typography.variants.body2Strong.size,
fontFamily: t.typography.variants.body2Strong.face,

Просмотреть файл

@ -1,4 +1,3 @@
import { immutableMerge } from '@fluentui-react-native/immutable-merge';
import type { Theme } from '@fluentui-react-native/theme-types';
@ -9,16 +8,15 @@ import { defaultFABColorTokens } from './FABColorTokens';
import { defaultFABTokens } from './FABTokens';
import { defaultToggleButtonColorTokens } from './ToggleButtonColorTokens';
export const defaultButtonTheme = (theme: Theme) =>
({
export const defaultButtonTheme = (theme: Theme) => ({
components: {
Button: immutableMerge<object>(defaultButtonColorTokens(theme), defaultButtonFontTokens(theme), defaultButtonTokens(theme)),
FAB: immutableMerge<object>(defaultFABTokens(theme), defaultFABColorTokens(theme)),
ToggleButton:
immutableMerge<object>(
ToggleButton: immutableMerge<object>(
defaultButtonTokens(theme),
defaultButtonFontTokens(theme),
defaultButtonColorTokens(theme),
defaultToggleButtonColorTokens(theme)),
}
defaultToggleButtonColorTokens(theme),
),
},
});

Просмотреть файл

@ -3,8 +3,7 @@ import type { DimensionValue } from 'react-native';
import { globalTokensAndroid as globalTokens } from '@fluentui-react-native/theme-tokens';
import type { Theme } from '@fluentui-react-native/theme-types';
export const defaultButtonTokens = (_t: Theme) =>
({
export const defaultButtonTokens = (_t: Theme) => ({
focused: {
borderWidth: globalTokens.stroke.width20,
borderInnerWidth: globalTokens.stroke.width10,
@ -92,5 +91,5 @@ export const defaultButtonTokens = (_t: Theme) =>
default:
return 'primary';
}
}
},
});

Просмотреть файл

@ -1,8 +1,7 @@
import { globalTokensAndroid as globalTokens } from '@fluentui-react-native/theme-tokens';
import type { Theme } from '@fluentui-react-native/theme-types';
export const defaultFABTokens = (t: Theme) =>
({
export const defaultFABTokens = (t: Theme) => ({
elevation: t.shadows.shadow8.key.blur,
disabled: {
elevation: 0,

Просмотреть файл

@ -7,7 +7,8 @@ import { getAndroidTheme } from './androidTheme';
import { defaultButtonTheme } from './components/Button/ButtonTheme';
export function createAndroidTheme(options: ThemeOptions = {}): ThemeReference {
const themeRef = new ThemeReference<Theme, PartialTheme>({} as Theme,
const themeRef = new ThemeReference<Theme, PartialTheme>(
{} as Theme,
() => {
// Stub out HC and darkElevated on Android
const current =
@ -16,7 +17,8 @@ export function createAndroidTheme(options: ThemeOptions = {}): ThemeReference {
: options.appearance;
return getAndroidTheme(current);
},
defaultButtonTheme);
defaultButtonTheme,
);
if (Appearance && options.appearance === 'dynamic') {
Appearance.addChangeListener(() => {

Просмотреть файл

@ -87,4 +87,4 @@ describe('verify types', () => {
const fabTokens: FABTokens = defaultFABTokens(officeTheme);
expect(fabTokens).toBeTruthy();
});
})
});

Просмотреть файл

@ -1,7 +1,6 @@
import type { Theme } from '@fluentui-react-native/theme-types';
export const defaultButtonColorTokens = (t: Theme) =>
({
export const defaultButtonColorTokens = (t: Theme) => ({
backgroundColor: t.colors.defaultBackground,
color: t.colors.defaultContent,
borderColor: t.colors.defaultBorder,

Просмотреть файл

@ -1,5 +1,3 @@
import type { Theme } from '@fluentui-react-native/theme-types';
export const defaultButtonColorTokens = (_t: Theme) =>
({
});
export const defaultButtonColorTokens = (_t: Theme) => ({});

Просмотреть файл

@ -1,7 +1,6 @@
import type { Theme } from '@fluentui-react-native/theme-types';
export const defaultButtonFontTokens = (t: Theme) =>
({
export const defaultButtonFontTokens = (t: Theme) => ({
medium: {
fontSize: t.typography.variants.caption1Strong!.size,
fontFamily: t.typography.variants.caption1Strong!.face,

Просмотреть файл

@ -1,7 +1,6 @@
import type { Theme } from '@fluentui-react-native/theme-types';
export const defaultButtonFontTokens = (_t: Theme) =>
({
export const defaultButtonFontTokens = (_t: Theme) => ({
medium: {
hasContent: {
variant: 'bodyStandard',

Просмотреть файл

@ -1,5 +1,3 @@
import type { Theme } from '@fluentui-react-native/theme-types';
export const defaultButtonFontTokens = (_t: Theme) =>
({
});
export const defaultButtonFontTokens = (_t: Theme) => ({});

Просмотреть файл

@ -1,4 +1,3 @@
import { immutableMerge } from '@fluentui-react-native/immutable-merge';
import type { Theme } from '@fluentui-react-native/theme-types';
@ -12,25 +11,24 @@ import { defaultFABColorTokens } from './FABColorTokens.ios';
import { defaultFABTokens } from './FABTokens.ios';
import { defaultToggleButtonColorTokens } from './ToggleButtonColorTokens';
export const defaultButtonTheme = (theme: Theme) =>
({
export const defaultButtonTheme = (theme: Theme) => ({
components: {
Button: immutableMerge<object>(defaultButtonColorTokens(theme), defaultButtonFontTokens(theme), defaultButtonTokens(theme)),
CompoundButton:
immutableMerge<object>(
CompoundButton: immutableMerge<object>(
defaultButtonTokens(theme),
defaultButtonColorTokens(theme),
defaultCompoundButtonColorTokens(theme),
defaultCompoundButtonFontTokens(theme),
defaultCompoundButtonTokens(theme)),
defaultCompoundButtonTokens(theme),
),
FAB: immutableMerge<object>(defaultFABTokens(theme), defaultFABColorTokens(theme)),
ToggleButton:
immutableMerge<object>(
ToggleButton: immutableMerge<object>(
defaultButtonTokens(theme),
defaultButtonFontTokens(theme),
defaultButtonColorTokens(theme),
defaultToggleButtonColorTokens(theme)),
}
defaultToggleButtonColorTokens(theme),
),
},
});

Просмотреть файл

@ -1,4 +1,3 @@
import { immutableMerge } from '@fluentui-react-native/immutable-merge';
import type { Theme } from '@fluentui-react-native/theme-types';
@ -10,23 +9,22 @@ import { defaultCompoundButtonFontTokens } from './CompoundButtonFontTokens';
import { defaultCompoundButtonTokens } from './CompoundButtonTokens';
import { defaultToggleButtonColorTokens } from './ToggleButtonColorTokens';
export const defaultButtonTheme = (theme: Theme) =>
({
export const defaultButtonTheme = (theme: Theme) => ({
components: {
Button: immutableMerge<object>(defaultButtonColorTokens(theme), defaultButtonFontTokens(theme), defaultButtonTokens(theme)),
CompoundButton:
immutableMerge<object>(
CompoundButton: immutableMerge<object>(
defaultButtonTokens(theme),
defaultButtonColorTokens(theme),
defaultCompoundButtonColorTokens(theme),
defaultCompoundButtonFontTokens(theme),
defaultCompoundButtonTokens(theme)),
defaultCompoundButtonTokens(theme),
),
ToggleButton:
immutableMerge<object>(
ToggleButton: immutableMerge<object>(
defaultButtonTokens(theme),
defaultButtonFontTokens(theme),
defaultButtonColorTokens(theme),
defaultToggleButtonColorTokens(theme)),
}
defaultToggleButtonColorTokens(theme),
),
},
});

Просмотреть файл

@ -3,8 +3,7 @@ import type { DimensionValue } from 'react-native';
import { globalTokensIOS as globalTokens } from '@fluentui-react-native/theme-tokens';
import type { Theme } from '@fluentui-react-native/theme-types';
export const defaultButtonTokens = (_t: Theme) =>
({
export const defaultButtonTokens = (_t: Theme) => ({
block: {
width: '100%' as DimensionValue,
},
@ -73,7 +72,6 @@ export const defaultButtonTokens = (_t: Theme) =>
borderRadius: globalTokens.corner.radiusNone,
},
getPlatformSpecificAppearance: (appearance): 'accent' | 'primary' | 'subtle' | 'outline' => {
switch (appearance) {
case 'accent': // Included to cover Mobile platform naming guidelines, maps to 'primary'.
return 'primary';
@ -86,5 +84,5 @@ export const defaultButtonTokens = (_t: Theme) =>
default:
return 'primary';
}
}
},
});

Просмотреть файл

@ -3,8 +3,7 @@ import type { DimensionValue } from 'react-native';
import { globalTokens } from '@fluentui-react-native/theme-tokens';
import type { Theme } from '@fluentui-react-native/theme-types';
export const defaultButtonTokens = (_t: Theme) =>
({
export const defaultButtonTokens = (_t: Theme) => ({
block: {
width: '100%' as DimensionValue,
},
@ -97,5 +96,5 @@ export const defaultButtonTokens = (_t: Theme) =>
default:
return null;
}
}
},
});

Просмотреть файл

@ -1,8 +1,7 @@
import { globalTokensIOS as globalTokens } from '@fluentui-react-native/theme-tokens';
import type { Theme } from '@fluentui-react-native/theme-types';
export const defaultFABTokens = (t: Theme) =>
({
export const defaultFABTokens = (t: Theme) => ({
shadowToken: t.shadows.shadow8,
disabled: {
shadowToken: t.shadows.shadow2,

Просмотреть файл

@ -8,11 +8,15 @@ import { getBaseAppleThemeIOS } from './appleTheme.ios';
import { defaultButtonTheme } from './components/Button/ButtonTheme';
export function createAppleTheme(): ThemeReference {
const appleThemeReference = new ThemeReference<Theme, PartialTheme>({} as Theme, () => {
const appleThemeReference = new ThemeReference<Theme, PartialTheme>(
{} as Theme,
() => {
const isLightMode = Appearance.getColorScheme() === 'light';
const isElevated = NativeAppearanceAdditions.userInterfaceLevel() === 'elevated';
return getBaseAppleThemeIOS(isLightMode, isElevated);
}, defaultButtonTheme);
},
defaultButtonTheme,
);
Appearance.addChangeListener(() => {
appleThemeReference.invalidate();

Просмотреть файл

@ -13,11 +13,15 @@ import { defaultButtonTheme } from './components/Button/ButtonTheme';
let appleThemeReference: ThemeReference;
export function createAppleTheme(): ThemeReference {
appleThemeReference = new ThemeReference<Theme, PartialTheme>({} as Theme, () => {
appleThemeReference = new ThemeReference<Theme, PartialTheme>(
{} as Theme,
() => {
const appearance = Appearance.getColorScheme();
const mode = getCurrentAppearance(appearance, 'light');
return getBaseAppleThemeMacOS(mode);
}, defaultButtonTheme);
},
defaultButtonTheme,
);
// Fetch initial system settings for high contrast mode
highContrastHandler();
// Invalidate theme and set prop when high contrast setting changes

Просмотреть файл

@ -1,7 +1,6 @@
import type { Theme } from '@fluentui-react-native/theme-types';
export const defaultButtonColorTokens = (t: Theme) =>
({
export const defaultButtonColorTokens = (t: Theme) => ({
backgroundColor: t.colors.buttonBackground,
color: t.colors.buttonText,
borderColor: t.colors.buttonBorder,

Просмотреть файл

@ -2,8 +2,7 @@ import type { Theme } from '@fluentui-react-native/theme-types';
type fontVariantType = 'secondaryStandard' | 'bodyStandard';
export const defaultButtonFontTokens = (_t: Theme) =>
({
export const defaultButtonFontTokens = (_t: Theme) => ({
medium: {
hasContent: {
variant: 'bodySemibold' as fontVariantType,

Просмотреть файл

@ -1,4 +1,3 @@
import { immutableMerge } from '@fluentui-react-native/immutable-merge';
import type { Theme } from '@fluentui-react-native/theme-types';
@ -10,25 +9,21 @@ import { defaultCompoundButtonFontTokens } from './CompoundButtonFontTokens';
import { defaultCompoundButtonTokens } from './CompoundButtonTokens';
import { defaultToggleButtonColorTokens } from './ToggleButtonColorTokens';
export const defaultButtonTheme = (theme: Theme) =>
({
export const defaultButtonTheme = (theme: Theme) => ({
components: {
Button: immutableMerge<object>(
defaultButtonColorTokens(theme),
defaultButtonFontTokens(theme),
defaultButtonTokens(theme)),
CompoundButton:
immutableMerge<object>(
Button: immutableMerge<object>(defaultButtonColorTokens(theme), defaultButtonFontTokens(theme), defaultButtonTokens(theme)),
CompoundButton: immutableMerge<object>(
defaultButtonTokens(theme),
defaultButtonColorTokens(theme),
defaultCompoundButtonColorTokens(theme),
defaultCompoundButtonFontTokens(theme),
defaultCompoundButtonTokens(theme)),
ToggleButton:
immutableMerge<object>(
defaultCompoundButtonTokens(theme),
),
ToggleButton: immutableMerge<object>(
defaultButtonTokens(theme),
defaultButtonFontTokens(theme),
defaultButtonColorTokens(theme),
defaultToggleButtonColorTokens(theme)),
}
defaultToggleButtonColorTokens(theme),
),
},
});

Просмотреть файл

@ -3,8 +3,7 @@ import type { DimensionValue } from 'react-native';
import { globalTokens } from '@fluentui-react-native/theme-tokens';
import type { Theme } from '@fluentui-react-native/theme-types';
export const defaultButtonTokens = (_t: Theme) =>
({
export const defaultButtonTokens = (_t: Theme) => ({
block: {
width: '100%' as DimensionValue,
},
@ -98,6 +97,5 @@ getPlatformSpecificAppearance: (appearance): 'primary' | 'subtle' | 'outline' |
default:
return null;
}
}
},
});

Просмотреть файл

@ -9,7 +9,9 @@ import { defaultButtonTheme } from './components/Button/ButtonTheme';
import { defaultFluentDarkTheme, defaultFluentHighConstrastTheme, defaultFluentTheme } from './defaultTheme';
export function createDefaultTheme(options: ThemeOptions = {}): ThemeReference {
const themeRef = new ThemeReference<Theme, PartialTheme>({} as Theme, () => {
const themeRef = new ThemeReference<Theme, PartialTheme>(
{} as Theme,
() => {
const current = getCurrentAppearance(options.appearance, options.defaultAppearance || 'light');
switch (current) {
case 'light':
@ -23,7 +25,9 @@ export function createDefaultTheme(options: ThemeOptions = {}): ThemeReference {
default:
assertNever(current);
}
}, defaultButtonTheme);
},
defaultButtonTheme,
);
if (Appearance && options.appearance === 'dynamic') {
Appearance.addChangeListener(() => {

Просмотреть файл

@ -120,4 +120,4 @@ describe('verify types', () => {
const compoundButtonTokens: CompoundButtonTokens = defaultCompoundButtonTokens(officeTheme);
expect(compoundButtonTokens).toBeTruthy();
});
})
});

Просмотреть файл

@ -1,9 +1,8 @@
import { globalTokensWin32 as globalTokens } from '@fluentui-react-native/theme-tokens';
import type { Theme } from '@fluentui-react-native/theme-types';
import type { FontWeight } from '@fluentui-react-native/theme-types'
import type { FontWeight } from '@fluentui-react-native/theme-types';
export const defaultButtonFontTokens = (t: Theme) =>
({
export const defaultButtonFontTokens = (t: Theme) => ({
medium: {
hasContent: {
fontFamily: t.typography.families.secondary,

Просмотреть файл

@ -1,4 +1,3 @@
import { immutableMerge } from '@fluentui-react-native/immutable-merge';
import type { Theme } from '@fluentui-react-native/theme-types';
@ -10,25 +9,21 @@ import { defaultCompoundButtonFontTokens } from './CompoundButtonFontTokens';
import { defaultCompoundButtonTokens } from './CompoundButtonTokens';
import { defaultToggleButtonColorTokens } from './ToggleButtonColorTokens';
export const defaultButtonTheme = (theme: Theme) =>
({
export const defaultButtonTheme = (theme: Theme) => ({
components: {
Button: immutableMerge<object>(
defaultButtonColorTokens(theme),
defaultButtonFontTokens(theme),
defaultButtonTokens(theme)),
CompoundButton:
immutableMerge<object>(
Button: immutableMerge<object>(defaultButtonColorTokens(theme), defaultButtonFontTokens(theme), defaultButtonTokens(theme)),
CompoundButton: immutableMerge<object>(
defaultButtonTokens(theme),
defaultButtonColorTokens(theme),
defaultCompoundButtonColorTokens(theme),
defaultCompoundButtonFontTokens(theme),
defaultCompoundButtonTokens(theme)),
ToggleButton:
immutableMerge<object>(
defaultCompoundButtonTokens(theme),
),
ToggleButton: immutableMerge<object>(
defaultButtonTokens(theme),
defaultButtonFontTokens(theme),
defaultButtonColorTokens(theme),
defaultToggleButtonColorTokens(theme)),
}
defaultToggleButtonColorTokens(theme),
),
},
});

Просмотреть файл

@ -6,8 +6,7 @@ import { isHighContrast } from '@fluentui-react-native/theming-utils';
type ButtonSize = 'small';
export const defaultButtonTokens = (theme: Theme) =>
({
export const defaultButtonTokens = (theme: Theme) => ({
size: 'small' as ButtonSize,
borderWidth: globalTokens.stroke.width10,
borderInnerWidth: globalTokens.stroke.width10,
@ -179,5 +178,5 @@ export const defaultButtonTokens = (theme: Theme) =>
default:
return null;
}
}
},
});

Просмотреть файл

@ -46,7 +46,7 @@ export const defaultCompoundButtonColorTokens = (t: Theme) => {
secondaryContentColor: t.colors.neutralForeground2Pressed,
},
},
}
};
};
const highContrastColors = {