Skip to content

Commit

Permalink
MUK035: Implement Popup component and its' stories + implement helper…
Browse files Browse the repository at this point in the history
… EqualSidesContainer component and its' props
  • Loading branch information
kuzkokov committed May 17, 2024
1 parent 3d3b46b commit 7ee93f2
Show file tree
Hide file tree
Showing 8 changed files with 429 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Label, LabelProps } from '@appello/mobile-ui';
import type { Meta, StoryObj } from '@storybook/react';
import React from 'react';

import { CONFIG_CATEGORY } from '../../constants';

const meta = {
title: 'Basic/Label',
component: Label,
render: ({ ...restProps }) => {
return <Label {...restProps} />;
},
args: {
children: 'Label',
bgColor: '#1C88EC',
textColor: '#fff',
},
argTypes: {
textProps: {
table: {
category: CONFIG_CATEGORY,
},
},
},
} satisfies Meta<LabelProps>;

type Story = StoryObj<LabelProps>;

export const DefaultStory: Story = {};

export default meta;
33 changes: 16 additions & 17 deletions .storybook/stories/Label/Label.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
import { Label, LabelProps } from '@appello/mobile-ui';
import { AppText, EqualSidesContainer, EqualSidesContainerProps } from '@appello/mobile-ui';
import type { Meta, StoryObj } from '@storybook/react';
import React from 'react';

import { CONFIG_CATEGORY } from '../../constants';

const meta = {
title: 'Basic/Label',
component: Label,
render: ({ ...restProps }) => {
return <Label {...restProps} />;
},
title: 'Basic/EqualSidesContainer',
component: EqualSidesContainer,
args: {
children: 'Label',
bgColor: '#1C88EC',
textColor: '#fff',
children: <AppText variant="h3">DD</AppText>,
bgColor: '#FDD835',
size: 100,
},
argTypes: {
textProps: {
table: {
category: CONFIG_CATEGORY,
},
bgColor: {
control: 'color',
},
children: {
control: false,
},
borderRadius: {
control: 'number',
},
},
} satisfies Meta<LabelProps>;
} satisfies Meta<EqualSidesContainerProps>;

type Story = StoryObj<LabelProps>;
type Story = StoryObj<EqualSidesContainerProps>;

export const DefaultStory: Story = {};

Expand Down
90 changes: 90 additions & 0 deletions .storybook/stories/Popup/Popup.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { Button, ButtonProps, EqualSidesContainer, Popup, PopupProps } from '@appello/mobile-ui';
import CalendarIcon from '@appello/mobile-ui/icons/unicons/calendar.svg';
import { BottomSheetModalProvider } from '@gorhom/bottom-sheet';
import type { Meta, StoryObj } from '@storybook/react';
import React, { useEffect, useMemo, useState } from 'react';

const meta = {
title: 'Basic/Popup',
component: Popup,
render: ({ opened: propOpened, onClose, buttons, topAccessory, ...props }) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const [opened, setOpened] = useState(false);
// eslint-disable-next-line react-hooks/rules-of-hooks
useEffect(() => {
setOpened(!!propOpened);
}, [propOpened]);

const closePopup = () => setOpened(false);

const CloseButton: ButtonProps = {
children: 'Close',
variant: 'primary',
onPress: closePopup,
};
const CancelButton: ButtonProps = {
children: 'Cancel',
variant: 'secondary',
onPress: closePopup,
};
const OkButton: ButtonProps = {
children: 'Ok',
variant: 'secondary',
onPress: closePopup,
};

// eslint-disable-next-line react-hooks/rules-of-hooks
const buttonProps = useMemo<PopupProps['buttons'] | undefined>(() => {
const buttonsToShow = buttons as unknown as 'none' | 'one' | 'two' | 'three';
if (buttonsToShow === 'one') return [CloseButton];
if (buttonsToShow === 'two') return [CancelButton, CloseButton];
if (buttonsToShow === 'three') return [CancelButton, OkButton, CloseButton];

return undefined;
}, [buttons]);

// eslint-disable-next-line react-hooks/rules-of-hooks
const renderTopAccessory = useMemo(
() => (
<EqualSidesContainer bgColor="#F9F9FB" borderRadius="rounded" size={110}>
<CalendarIcon height={38} width={38} />
</EqualSidesContainer>
),
[],
);

return (
<BottomSheetModalProvider>
<Button variant="primary" onPress={() => setOpened(true)}>
Open popup
</Button>
<Popup
buttons={buttonProps}
opened={opened}
topAccessory={topAccessory ? renderTopAccessory : undefined}
onClose={onClose ? closePopup : undefined}
{...props}
/>
</BottomSheetModalProvider>
);
},
args: {
opened: false,
title: 'Title',
message: 'Lorem ipsum dolor sit amet, consecteturadipiscing elit. Congue velit massa non.',
},
argTypes: {
onClose: { control: 'boolean' },
topAccessory: { control: 'boolean' },
buttons: {
control: 'radio',
options: ['none', 'one', 'two', 'three'],
},
},
} satisfies Meta<PopupProps>;

type Story = StoryObj<PopupProps>;

export const DefaultStory: Story = {};

export default meta;
33 changes: 17 additions & 16 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ PODS:
- boost (1.83.0)
- CocoaAsyncSocket (7.6.5)
- DoubleConversion (1.1.6)
- EXApplication (5.8.3):
- EXApplication (5.8.4):
- ExpoModulesCore
- EXConstants (15.4.5):
- EXConstants (15.4.6):
- ExpoModulesCore
- EXFont (11.10.3):
- ExpoModulesCore
- EXJSONUtils (0.12.3)
- EXManifests (0.13.2):
- ExpoModulesCore
- Expo (50.0.12):
- Expo (50.0.18):
- ExpoModulesCore
- expo-dev-client (3.3.11):
- EXManifests
Expand Down Expand Up @@ -80,13 +80,13 @@ PODS:
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- ExpoFileSystem (16.0.8):
- ExpoFileSystem (16.0.9):
- ExpoModulesCore
- ExpoKeepAwake (12.8.2):
- ExpoModulesCore
- ExpoLinearGradient (12.7.2):
- ExpoModulesCore
- ExpoModulesCore (1.11.11):
- ExpoModulesCore (1.11.13):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
Expand Down Expand Up @@ -1209,7 +1209,7 @@ PODS:
- React-jsi (= 0.73.6)
- React-logger (= 0.73.6)
- React-perflogger (= 0.73.6)
- RNBootSplash (5.4.1):
- RNBootSplash (5.5.3):
- React-Core
- RNCAsyncStorage (1.21.0):
- React-Core
Expand All @@ -1222,11 +1222,12 @@ PODS:
- RCT-Folly (= 2022.05.16.00)
- React-Core
- ReactCommon/turbomodule/core
- RNScreens (3.29.0):
- RNScreens (3.31.1):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
- RNSVG (14.1.0):
- React-RCTImage
- RNSVG (14.2.0):
- React-Core
- SocketRocket (0.6.1)
- Yoga (1.14.0)
Expand Down Expand Up @@ -1494,20 +1495,20 @@ SPEC CHECKSUMS:
boost: d3f49c53809116a5d38da093a8aa78bf551aed09
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
DoubleConversion: fea03f2699887d960129cc54bba7e52542b6f953
EXApplication: 137189a3f149b4e8e546884629392c3efc94cbd3
EXConstants: 988aa430ca0f76b43cd46b66e7fae3287f9cc2fc
EXApplication: 16bcea16789221bd566e64b5ea2608cf7756b005
EXConstants: a5f6276e565d98f9eb4280f81241fc342d641590
EXFont: f20669cb266ef48b004f1eb1f2b20db96cd1df9f
EXJSONUtils: 5c42959e87be238b045ef37cc5268b16a6c0ad4a
EXManifests: 5e8c29f36c716af768a4ea47ec05e1b89ab93091
Expo: 586874ad360bc2516adf68ae591911b54b7e7c73
Expo: 09bd48f31bb7f1a3c97fd5a6cb28feae89cb4e40
expo-dev-client: 29a32387346fe7b6d2a57918fae985bc48bfe9a2
expo-dev-launcher: f45e0f751addcc5ff891e0446e4762508b9030f2
expo-dev-menu: 0e07e86ed397e431ee1171bb26caf7dc69cb494d
expo-dev-menu-interface: 7ba029c9d1a82ac22b9b584c00514860b060553e
ExpoFileSystem: eecaf6796aed0f4dd20042dc2ca2cac6c4bc1185
ExpoFileSystem: 74cc0fae916f9f044248433971dcfc8c3befd057
ExpoKeepAwake: 0f5cad99603a3268e50af9a6eb8b76d0d9ac956c
ExpoLinearGradient: 4ad1449a2408e0435ac959076562b3921f2e32a1
ExpoModulesCore: 304ccb25e6365959e4d23a683f6c3fd425f96b1f
ExpoModulesCore: 4a8928a228569301ac4fc4a1e846713e05754d05
EXUpdatesInterface: 3e444e2093e25b7ca0999a7d8c16e8392dee70c3
FBLazyVector: f64d1e2ea739b4d8f7e4740cde18089cd97fe864
FBReactNativeSpec: 9f2b8b243131565335437dba74923a8d3015e780
Expand Down Expand Up @@ -1567,12 +1568,12 @@ SPEC CHECKSUMS:
React-runtimescheduler: 9636eee762c699ca7c85751a359101797e4c8b3b
React-utils: d16c1d2251c088ad817996621947d0ac8167b46c
ReactCommon: 2aa35648354bd4c4665b9a5084a7d37097b89c10
RNBootSplash: eff8239c4f795ce42a0604873aef3733aac0dedd
RNBootSplash: e025d4ee98d942ee6c8b495a6fe66339a6b5f6dd
RNCAsyncStorage: 618d03a5f52fbccb3d7010076bc54712844c18ef
RNGestureHandler: 15c6ef51acba34c49ff03003806cf5dd6098f383
RNReanimated: f6b02d8f5eaa2830296411d4ec3b8ef5442dd13d
RNScreens: 17e2f657f1b09a71ec3c821368a04acbb7ebcb46
RNSVG: ba3e7232f45e34b7b47e74472386cf4e1a676d0a
RNScreens: 134a7511b12b8eb440b87aac21e36a71295d6024
RNSVG: 963a95f1f5d512a13d11ffd50d351c87fb5c6890
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
Yoga: d17d2cc8105eed528474683b42e2ea310e1daf61

Expand Down
56 changes: 56 additions & 0 deletions src/components/common/EqualSidesContainer/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React from 'react';
import { ColorValue, TouchableOpacity, TouchableOpacityProps } from 'react-native';

import { makeStyles } from '../../../utils';

export interface EqualSidesContainerProps extends TouchableOpacityProps {
/**
* Width and height of the container
* */
size: number;
/**
* Color of the container background
* */
bgColor?: ColorValue;
/**
* Border radius of the container.<br>
* Could have a specific value if passed as a number or just be round.
* */
borderRadius?: 'rounded' | number;
}

/**
* Simple helper component mostly used as a background for icons
* */
export const EqualSidesContainer: React.FC<EqualSidesContainerProps> = ({
style,
borderRadius,
onPress,
bgColor,
size,
...touchableProps
}) => {
const styles = useStyles({ borderRadius, bgColor, size });

return (
<TouchableOpacity
{...touchableProps}
disabled={!onPress}
style={[styles.container, style]}
onPress={onPress}
/>
);
};

const useStyles = makeStyles(
(theme, { size, bgColor, borderRadius }: EqualSidesContainerProps) => ({
container: {
width: size,
height: size,
alignItems: 'center',
justifyContent: 'center',
borderRadius: borderRadius === 'rounded' ? size / 2 : borderRadius,
backgroundColor: bgColor,
},
}),
);
Loading

0 comments on commit 7ee93f2

Please sign in to comment.