Skip to content
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

[IOAPPFD0-154] Fix UI regressions affecting Button… and LabelLink components #80

Merged
merged 5 commits into from
Sep 22, 2023
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
25 changes: 20 additions & 5 deletions example/src/pages/Buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ import { ComponentViewerBox } from "../components/ComponentViewerBox";
import { Screen } from "../components/Screen";

const styles = StyleSheet.create({
primaryBlockLegacy: {
backgroundColor: IOColors.blue,
padding: 16,
borderRadius: 8
},
primaryBlock: {
backgroundColor: IOColors["blueIO-500"],
padding: 16,
Expand Down Expand Up @@ -186,7 +191,9 @@ export const Buttons = () => {
</View>
</ComponentViewerBox>

<View style={styles.primaryBlock}>
<View
style={isExperimental ? styles.primaryBlock : styles.primaryBlockLegacy}
>
<ComponentViewerBox
name="ButtonSolid · Contrast variant"
colorMode="dark"
Expand Down Expand Up @@ -342,7 +349,9 @@ export const Buttons = () => {
</View>
</ComponentViewerBox>

<View style={styles.primaryBlock}>
<View
style={isExperimental ? styles.primaryBlock : styles.primaryBlockLegacy}
>
<ComponentViewerBox
name="ButtonOutline · Contrast variant"
colorMode="dark"
Expand Down Expand Up @@ -555,7 +564,9 @@ export const Buttons = () => {
</View>
</ComponentViewerBox>

<View style={styles.primaryBlock}>
<View
style={isExperimental ? styles.primaryBlock : styles.primaryBlockLegacy}
>
<ComponentViewerBox
name="IconButton · Contrast variant"
colorMode="dark"
Expand Down Expand Up @@ -626,7 +637,9 @@ export const Buttons = () => {
</View>
</ComponentViewerBox>

<View style={styles.primaryBlock}>
<View
style={isExperimental ? styles.primaryBlock : styles.primaryBlockLegacy}
>
<ComponentViewerBox
name="IconButtonSolid · Contrast variant, large"
colorMode="dark"
Expand Down Expand Up @@ -706,7 +719,9 @@ export const Buttons = () => {
</View>
</ComponentViewerBox>

<View style={styles.primaryBlock}>
<View
style={isExperimental ? styles.primaryBlock : styles.primaryBlockLegacy}
>
<ComponentViewerBox
name="IconButtonContained · Contrast variant"
colorMode="dark"
Expand Down
9 changes: 7 additions & 2 deletions src/components/buttons/ButtonLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ import {
} from "../../core";
import { makeFontStyleObject } from "../../utils/fonts";
import { WithTestID } from "../../utils/types";
import { AnimatedIcon, IOIcons, IconClassComponent } from "../icons/Icon";
import {
AnimatedIcon,
IOIconSizeScale,
IOIcons,
IconClassComponent
} from "../icons";
import { HSpacer } from "../spacer/Spacer";
import { buttonTextFontSize } from "../typography";

Expand Down Expand Up @@ -175,7 +180,7 @@ export const ButtonLink = React.memo(
}, [isPressed]);

// Icon size
const iconSize = 24;
const iconSize: IOIconSizeScale = 24;

return (
<Pressable
Expand Down
12 changes: 11 additions & 1 deletion src/components/buttons/ButtonOutline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ import {
} from "../../core/";
import { makeFontStyleObject } from "../../utils/fonts";
import { WithTestID } from "../../utils/types";
import { AnimatedIcon, IOIcons, IconClassComponent } from "../icons";
import {
AnimatedIcon,
IOIconSizeScale,
IOIcons,
IconClassComponent
} from "../icons";
import { HSpacer } from "../spacer/Spacer";
import { buttonTextFontSize } from "../typography";

Expand Down Expand Up @@ -191,6 +196,9 @@ const IOButtonLegacyStylesLocal = StyleSheet.create({
}
});

// Icon size
const iconSize: IOIconSizeScale = 20;

const DISABLED_OPACITY = 0.5;

const IOButtonStylesLocal = StyleSheet.create({
Expand Down Expand Up @@ -349,11 +357,13 @@ export const ButtonOutline = ({
name={icon}
animatedProps={pressedColorIconAnimationStyle}
color={colorMap[color]?.label?.default}
size={iconSize}
/>
) : (
<AnimatedIcon
name={icon}
color={colorMap[color]?.label?.disabled}
size={iconSize}
/>
)}
<HSpacer size={8} />
Expand Down
22 changes: 8 additions & 14 deletions src/components/buttons/ButtonSolid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import Animated, {
useSharedValue,
withSpring
} from "react-native-reanimated";
import { IOIcons, Icon } from "../icons";
import { IOIconSizeScale, IOIcons, Icon } from "../icons";
import { WithTestID } from "../../utils/types";
import { HSpacer } from "../spacer/Spacer";
import { ButtonText, ButtonTextAllowedColors } from "../typography/ButtonText";
import { ButtonText } from "../typography/ButtonText";
import {
IOButtonLegacyStyles,
IOButtonStyles,
Expand All @@ -28,8 +28,8 @@ type ColorStates = {
default: string;
pressed: string;
label: {
default: ButtonTextAllowedColors;
disabled: ButtonTextAllowedColors;
default: IOColors;
disabled: IOColors;
};
};

Expand All @@ -45,6 +45,9 @@ const legacyStyles = StyleSheet.create({
const colorPrimaryButtonDisabled: IOColors = "grey-200";
const DISABLED_OPACITY = 0.5;

// Icon size
const iconSize: IOIconSizeScale = 20;

const styles = StyleSheet.create({
backgroundDisabled: {
backgroundColor: IOColors[colorPrimaryButtonDisabled],
Expand All @@ -58,11 +61,6 @@ export type ButtonSolidProps = WithTestID<{
*/
color?: ButtonSolidColor;
label: string;
/**
* Renders a small variant of the button. This property applies to the legacy look only
* @default false
*/
small?: boolean;
/**
* @default false
*/
Expand Down Expand Up @@ -142,7 +140,7 @@ const mapLegacyColorStates: Record<
default: IOColors.white,
pressed: IOColors["blue-50"],
label: {
default: "blueIO-500",
default: "blue",
disabled: "white"
}
}
Expand All @@ -152,7 +150,6 @@ export const ButtonSolid = React.memo(
({
color = "primary",
label,
small = false,
fullWidth = false,
disabled = false,
icon,
Expand All @@ -177,9 +174,6 @@ export const ButtonSolid = React.memo(
[isExperimental]
);

// Icon size
const iconSize = React.useMemo(() => (small ? 16 : 20), [small]);

// Using a spring-based animation for our interpolations
const progressPressed = useDerivedValue(() =>
withSpring(isPressed.value, IOSpringValues.button)
Expand Down
5 changes: 1 addition & 4 deletions src/components/typography/ButtonText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import { useIOExperimentalDesign } from "../../core";
import { useTypographyFactory } from "./Factory";
import { ExternalTypographyProps, TypographyProps } from "./common";

export type ButtonTextAllowedColors = Extract<
IOColors,
"white" | "blueIO-500" | "grey-700"
>;
export type ButtonTextAllowedColors = IOColors;
type AllowedWeight = Extract<IOFontWeight, "SemiBold" | "Regular" | "Bold">;

type ButtonTextProps = ExternalTypographyProps<
Expand Down
13 changes: 9 additions & 4 deletions src/components/typography/LabelLink.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IOFontFamily, IOFontWeight } from "../../utils/fonts";
import type { IOColors } from "../../core";
import { useIOExperimentalDesign, type IOColors } from "../../core";
import {
ExternalTypographyProps,
FontSize,
Expand All @@ -20,18 +20,22 @@ type LinkProps = ExternalTypographyProps<

const fontName: IOFontFamily = "TitilliumWeb";

export const linkLegacyDefaultColor: AllowedColors = "blue";

export const linkDefaultColor: AllowedColors = "blueIO-500";
export const linkDefaultWeight: AllowedWeight = "SemiBold";

/**
* `Link` typographic style
*/
export const LabelLink = (props: LinkProps) =>
useTypographyFactory<AllowedWeight, AllowedColors>({
export const LabelLink = (props: LinkProps) => {
const { isExperimental } = useIOExperimentalDesign();

return useTypographyFactory<AllowedWeight, AllowedColors>({
accessibilityRole: props.onPress ? "link" : undefined,
...props,
defaultWeight: linkDefaultWeight,
defaultColor: linkDefaultColor,
defaultColor: isExperimental ? linkDefaultColor : linkLegacyDefaultColor,
font: fontName,
fontStyle: {
fontSize: props.fontSize
Expand All @@ -43,3 +47,4 @@ export const LabelLink = (props: LinkProps) =>
textDecorationLine: "underline"
}
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -966,8 +966,8 @@ exports[`Test Typography Components LabelSmall Snapshot 5`] = `

exports[`Test Typography Components Link Snapshot 1`] = `
<Text
color="blueIO-500"
defaultColor="blueIO-500"
color="blue"
defaultColor="blue"
defaultWeight="SemiBold"
font="TitilliumWeb"
fontStyle={
Expand All @@ -985,7 +985,7 @@ exports[`Test Typography Components Link Snapshot 1`] = `
"textDecorationLine": "underline",
},
{
"color": "#0B3EE3",
"color": "#0073E6",
"fontFamily": "Titillium Web",
"fontStyle": "normal",
"fontWeight": "600",
Expand Down