Skip to content

Commit

Permalink
Created ButtonBase, Button, IconButton, and LinkButton docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Canciller committed Apr 13, 2022
1 parent 50d5ece commit e61f516
Show file tree
Hide file tree
Showing 71 changed files with 6,871 additions and 200 deletions.
4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ babel.config.js
cucumber.js
jest.config.js
jest.setup.js
metro.config.js
metro.config.js

website
2 changes: 2 additions & 0 deletions example/src/Calendars/Calendars.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export default function Calendars() {
<CalendarStrip ref={ref} value={value} onChange={setValue} />
<Body>{value.toLocaleDateString()}</Body>
<Button
variant="rounded"
text="Today"
color="primary"
onPress={() => {
setValue(new Date());
ref.current?.jumpToDate(new Date());
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
"private": true,
"workspaces": [
"example",
"website",
"packages/*"
],
"scripts": {
"start": "yarn workspace example start",
"start:website": "yarn workspace website start",
"build:theme": "yarn workspace @nomada-sh/react-native-eyecandy-theme build",
"build:icons": "yarn workspace @nomada-sh/react-native-eyecandy-icons build",
"build:components": "yarn workspace @nomada-sh/react-native-eyecandy build",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const getButtonColors: GetThemeColors<ThemeBackgroundColors> = options => {

return mergeColors({
...options,
defaultColors: defaultColors,
defaultColors,
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const getDividerColors: GetThemeColors<ThemeBadgeColors> = options => {

return mergeColors({
...options,
defaultColors: defaultColors,
defaultColors,
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ const getButtonColors: GetThemeColors<ThemeButtonColors> = options => {
background: palette.primary['500'],
foreground: palette.primary['100'],
},
secondary: {
background: palette.secondary['500'],
foreground: palette.secondary['100'],
},
};

return mergeColors({
...options,
defaultColors: defaultColors,
defaultColors,
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const getDividerColors: GetThemeColors<ThemeDividerColors> = options => {

return mergeColors({
...options,
defaultColors: defaultColors,
defaultColors,
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const getInputColors: GetThemeColors<ThemeInputColors> = options => {

return mergeColors({
...options,
defaultColors: defaultColors,
defaultColors,
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const getSwitchColors: GetThemeColors<ThemeSwitchColors> = options => {

return mergeColors({
...options,
defaultColors: defaultColors,
defaultColors,
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const getTextColors: GetThemeColors<ThemeTextColors> = options => {

return mergeColors({
...options,
defaultColors: defaultColors,
defaultColors,
});
};

Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-eyecandy-theme/src/colors/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export type ThemeBackgroundColors = {
* Button
*/

export type ThemeButtonColorChoices = 'default' | 'primary';
export type ThemeButtonColorChoices = 'default' | 'primary' | 'secondary';

export type ThemeButtonColor = {
background: string;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ function BaseMenuItem({
<View style={styles.content}>
{icon && (
<IconButton
variant="transparent-rounded"
variant="rounded"
transparent
style={styles.icon}
buttonStyle={{
pressableStyle={{
backgroundColor: iconBackgroundColor,
}}
icon={icon}
Expand Down
16 changes: 9 additions & 7 deletions packages/react-native-eyecandy/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import React from 'react';
import { TextStyle, StyleProp } from 'react-native';

import { Body } from '../../typography';
import BaseButton, { BaseButtonProps } from '../BaseButton';
import ButtonBase, { ButtonBaseProps } from '../ButtonBase';

import useStyles from './useStyles';

export interface ButtonProps extends Omit<BaseButtonProps, 'children'> {
text: string;
export interface ButtonProps extends Omit<ButtonBaseProps, 'children'> {
text?: string;
textStyle?: StyleProp<TextStyle>;
}

function Button({ text, color, inverse, ...props }: ButtonProps) {
function Button({ text, color, inverse, textStyle, ...props }: ButtonProps) {
const styles = useStyles({ color, inverse });

return (
<BaseButton color={color} inverse={inverse} {...props}>
<Body weight="bold" size="large" style={styles.text}>
<ButtonBase color={color} inverse={inverse} {...props}>
<Body weight="bold" size="large" style={[styles.text, textStyle]}>
{text}
</Body>
</BaseButton>
</ButtonBase>
);
}

Expand Down
15 changes: 5 additions & 10 deletions packages/react-native-eyecandy/src/components/Button/useStyles.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useMemo } from 'react';
import { StyleSheet } from 'react-native';

import {
Expand All @@ -15,13 +14,9 @@ export default function useStyles({
}) {
const { background, foreground } = useColors(c => c.button[color]);

return useMemo(
() =>
StyleSheet.create({
text: {
color: inverse ? background : foreground,
},
}),
[inverse, background, foreground],
);
return StyleSheet.create({
text: {
color: inverse ? background : foreground,
},
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
StyleProp,
View,
ViewStyle,
StyleSheet,
} from 'react-native';

import type { ThemeButtonColorChoices } from '@nomada-sh/react-native-eyecandy-theme';
Expand All @@ -16,7 +17,7 @@ import { usePressableStyles } from '../../hooks';

import useStyles from './useStyles';

export interface BaseButtonProps extends PressableProps {
export interface ButtonBaseProps extends PressableProps {
children?: ReactNode;
/**
* Container view style.
Expand All @@ -25,7 +26,7 @@ export interface BaseButtonProps extends PressableProps {
/**
* Pressable style.
*/
buttonStyle?: PressableProps['style'];
pressableStyle?: PressableProps['style'];
inverse?: boolean;
color?: ThemeButtonColorChoices;
styles?: {
Expand All @@ -38,17 +39,20 @@ export interface BaseButtonProps extends PressableProps {
*/
button?: PressableProps['style'];
};
variant?: 'default' | 'outlined' | 'rounded' | 'transparent-rounded';
variant?: 'default' | 'rounded';
height?: number;
fullwidth?: boolean;
loading?: boolean;
hideDisabledOverlay?: boolean;
transparent?: boolean;
outlined?: boolean;
disableHapticFeedback?: boolean;
}

function BaseButton({
function ButtonBase({
children,
style,
buttonStyle,
pressableStyle,
inverse,
color,
variant,
Expand All @@ -59,8 +63,11 @@ function BaseButton({
styles: customStyles = {},
hideDisabledOverlay,
onPress: onPressProp,
transparent,
outlined,
disableHapticFeedback = false,
...props
}: BaseButtonProps) {
}: ButtonBaseProps) {
const disabled = disabledProp || loading;

const styles = useStyles({
Expand All @@ -70,20 +77,23 @@ function BaseButton({
height,
disabled,
fullwidth,
transparent,
outlined,
});

const getButtonStyle = usePressableStyles([
styles.button,
buttonStyle,
styles.pressable,
pressableStyle,
customStyles.button,
]);

const onPress = useCallback(
(e: GestureResponderEvent) => {
ReactNativeHapticFeedback.trigger('impactMedium');
if (!disableHapticFeedback)
ReactNativeHapticFeedback.trigger('impactMedium');
onPressProp?.(e);
},
[onPressProp],
[disableHapticFeedback, onPressProp],
);

return (
Expand Down Expand Up @@ -111,4 +121,4 @@ function BaseButton({
);
}

export default BaseButton;
export default ButtonBase;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './ButtonBase';
export * from './ButtonBase';
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,57 @@ export default function useStyles({
height = 56,
disabled,
fullwidth = true,
transparent = false,
outlined = false,
}: {
color?: ThemeButtonColorChoices;
inverse?: boolean;
variant?: 'default' | 'outlined' | 'rounded' | 'transparent-rounded';
variant?: 'default' | 'rounded';
height?: number;
disabled?: boolean | null;
fullwidth?: boolean;
transparent?: boolean;
outlined?: boolean;
}) {
const colors = useColors(c => c.button);
const { background, foreground } = colors[color];

const borderRadius = /([a-z]+-)?rounded$/.test(variant) ? height / 2 : 12;
let borderWidth = 0;
let borderColor = undefined;
const borderRadius = variant === 'rounded' ? height / 2 : 12;

let backgroundColor = Color(inverse ? foreground : background).rgb();

const rippleColor = getRippleColor(backgroundColor);
const rippleColor = getRippleColor(backgroundColor).string();

let disabledColor = backgroundColor.fade(0.4);

if (/^transparent(-[a-z]+)?/.test(variant))
if (outlined) {
borderWidth = 1;
borderColor = inverse ? background : foreground;
backgroundColor = backgroundColor.alpha(0);
}

if (transparent) backgroundColor = backgroundColor.alpha(0);

return StyleSheet.create({
container: {
height,
borderRadius,
overflow: 'hidden',
width: fullwidth ? '100%' : undefined,
borderWidth,
borderColor,
},
button: {
pressable: {
flex: 1,
borderRadius,
backgroundColor: backgroundColor.string(),
justifyContent: 'center',
alignItems: 'center',
},
ripple: {
color: rippleColor.string(),
color: rippleColor,
},
disabled: {
backgroundColor: disabled ? disabledColor.string() : undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function DatePicker({
icon={CalendarEvent}
onPress={onPress}
text={formattedDate}
showChevron={false}
showChevronRight={false}
bold
focused={visible}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function Years({ onPressBack, year, maxYears, onPressYear }: YearsProps) {
>
<Button
onPress={() => onPressYear(y)}
buttonStyle={{
pressableStyle={{
height: 50,
}}
color={year === y ? 'primary' : 'default'}
Expand Down
Loading

0 comments on commit e61f516

Please sign in to comment.