-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IOPLT-112] Adds the FooterWithButtons component (#53)
## Short description This PR creates a new version of the footer with buttons with the new version of buttons from DS library ## How to test Check the specific page in the Example app to see how it changes. <img src="https://github.com/pagopa/io-app-design-system/assets/3959405/ac5f85b6-50d9-4001-94b8-7b604541199d" height="600"/> --------- Co-authored-by: Damiano Plebani <[email protected]>
- Loading branch information
1 parent
97bc7c4
commit 6c2c0a3
Showing
8 changed files
with
243 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import * as React from "react"; | ||
import { SafeAreaView, View } from "react-native"; | ||
import { | ||
H1, | ||
IOStyles, | ||
FooterWithButtons, | ||
VSpacer | ||
} from "@pagopa/io-app-design-system"; | ||
import { constVoid } from "fp-ts/lib/function"; | ||
import { Screen } from "../components/Screen"; | ||
|
||
/** | ||
* This Screen is used to test components in isolation while developing. | ||
* @returns a screen with a flexed view where you can test components | ||
*/ | ||
export const FooterWithButton = () => ( | ||
<SafeAreaView style={IOStyles.flex}> | ||
<View style={{ flexGrow: 1 }}> | ||
<Screen> | ||
<VSpacer /> | ||
<H1>Footer with button</H1> | ||
</Screen> | ||
<FooterWithButtons | ||
primary={{ | ||
type: "Solid", | ||
buttonProps: { | ||
color: "primary", | ||
accessibilityLabel: "primary button", | ||
onPress: constVoid, | ||
label: "Primary button" | ||
} | ||
}} | ||
secondary={{ | ||
type: "Outline", | ||
buttonProps: { | ||
color: "primary", | ||
fullWidth: true, | ||
accessibilityLabel: "secondary button", | ||
onPress: constVoid, | ||
label: "Secondary button" | ||
} | ||
}} | ||
type="TwoButtonsInlineHalf" | ||
/> | ||
</View> | ||
</SafeAreaView> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
import * as React from "react"; | ||
import { View, StyleSheet } from "react-native"; | ||
import { HSpacer } from "../spacer/Spacer"; | ||
import { ButtonOutline, ButtonSolid, ButtonSolidProps } from "../buttons"; | ||
import { IOStyles } from "../../core"; | ||
|
||
const styles = StyleSheet.create({ | ||
button: { | ||
alignContent: "center", | ||
justifyContent: "center", | ||
flex: 1 | ||
}, | ||
buttonTwoThirds: { | ||
alignContent: "center", | ||
flex: 2 | ||
} | ||
}); | ||
|
||
type CommonProps = Readonly<{ | ||
primary: BlockButtonProps; | ||
accessible?: boolean; | ||
}>; | ||
|
||
export type BlockButtonProps = { | ||
type: "Solid" | "Outline"; | ||
buttonProps: ButtonSolidProps; | ||
}; | ||
|
||
/** | ||
* | single button | | ||
*/ | ||
export interface SingleButton extends CommonProps { | ||
type: "SingleButton"; | ||
} | ||
|
||
/** | ||
* | left | right | | ||
*/ | ||
export interface TwoButtonsInlineHalf extends CommonProps { | ||
type: "TwoButtonsInlineHalf"; | ||
secondary: BlockButtonProps; | ||
} | ||
|
||
/** | ||
* | left | right | | ||
*/ | ||
interface TwoButtonsInlineThird extends CommonProps { | ||
type: "TwoButtonsInlineThird"; | ||
secondary: BlockButtonProps; | ||
} | ||
|
||
/** | ||
* | left | right | | ||
*/ | ||
interface TwoButtonsInlineThirdInverted extends CommonProps { | ||
type: "TwoButtonsInlineThirdInverted"; | ||
secondary: BlockButtonProps; | ||
} | ||
|
||
/** | ||
* | left | mid | right | | ||
*/ | ||
interface ThreeButtonsInLine extends CommonProps { | ||
type: "ThreeButtonsInLine"; | ||
secondary: BlockButtonProps; | ||
third: BlockButtonProps; | ||
} | ||
|
||
type Props = | ||
| SingleButton | ||
| TwoButtonsInlineHalf | ||
| TwoButtonsInlineThird | ||
| TwoButtonsInlineThirdInverted | ||
| ThreeButtonsInLine; | ||
|
||
export type BlockButtonsProps = Props; | ||
|
||
/** | ||
* Implements a component that show buttons on a line on 1, 2 or 3 buttons | ||
*/ | ||
export const BlockButtons = (props: Props) => { | ||
const renderRightButton = () => { | ||
if (props.type === "SingleButton") { | ||
return null; | ||
} | ||
|
||
const secondaryButtonStyle = | ||
props.type === "TwoButtonsInlineThird" | ||
? styles.buttonTwoThirds | ||
: styles.button; | ||
|
||
return ( | ||
<React.Fragment> | ||
<HSpacer size={16} /> | ||
{renderButton(props.secondary, secondaryButtonStyle)} | ||
</React.Fragment> | ||
); | ||
}; | ||
|
||
const renderMidButton = () => { | ||
if (props.type !== "ThreeButtonsInLine") { | ||
return null; | ||
} | ||
|
||
return ( | ||
<React.Fragment> | ||
<HSpacer size={16} /> | ||
{renderButton(props.third, styles.button)} | ||
</React.Fragment> | ||
); | ||
}; | ||
|
||
const renderLeftButton = () => { | ||
const primaryButtonStyle = | ||
props.type === "TwoButtonsInlineThirdInverted" | ||
? styles.buttonTwoThirds | ||
: styles.button; | ||
|
||
return renderButton(props.primary, primaryButtonStyle); | ||
}; | ||
|
||
const renderButton = ( | ||
props: BlockButtonProps, | ||
style: React.ComponentProps<typeof View>["style"] | ||
) => ( | ||
<View style={style}> | ||
{props.type === "Solid" ? ( | ||
<ButtonSolid {...props.buttonProps} /> | ||
) : ( | ||
<ButtonOutline {...props.buttonProps} /> | ||
)} | ||
</View> | ||
); | ||
|
||
return ( | ||
<View style={{ ...IOStyles.flex, ...IOStyles.row }}> | ||
{renderLeftButton()} | ||
{renderMidButton()} | ||
{renderRightButton()} | ||
</View> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import * as React from "react"; | ||
|
||
import { StyleSheet, View } from "react-native"; | ||
import { IOStyles } from "../../core"; | ||
import { BlockButtons, BlockButtonsProps } from "./BlockButtons"; | ||
|
||
// TODO: Refactor with an unique component like `FooterTopShadow` after bonus vacanze | ||
const styles = StyleSheet.create({ | ||
container: { | ||
overflow: "hidden", | ||
width: "100%", | ||
// This Magic number is an heritage of the app code-base, this component should be removed in favor of `GradientBottomAction` | ||
marginTop: -50, | ||
paddingTop: 50, | ||
position: "absolute", | ||
bottom: 0 | ||
} | ||
}); | ||
|
||
/** | ||
* Implements a component that show buttons as sticky footer | ||
* It can include 1, 2 or 3 buttons. If they are 2, they can have the inlineHalf or the inlineOneThird style | ||
*/ | ||
export const FooterWithButtons = (props: BlockButtonsProps) => ( | ||
<View | ||
style={styles.container} | ||
accessible={props.accessible} | ||
pointerEvents={"box-none"} | ||
testID="FooterWithButtons" | ||
> | ||
<View style={IOStyles.footer}> | ||
<BlockButtons {...props} /> | ||
</View> | ||
</View> | ||
); | ||
|
||
export default FooterWithButtons; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters