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

[IOPLT-94] Creating showcase for dividers and spacers #23

Merged
merged 4 commits into from
Jul 21, 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
71 changes: 71 additions & 0 deletions example/src/components/SpacerViewerBox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import {
HSpacer,
IOColors,
IOSpacer,
IOThemeContext,
SpacerOrientation,
VSpacer
} from "@pagopa/io-app-design-system";
import React, { useContext } from "react";
import { Text, View } from "react-native";

type SpacerViewerBoxProps = {
size: IOSpacer;
orientation?: SpacerOrientation;
};

const SpacerLabel = ({ value }: { value: IOSpacer }) => {
const theme = useContext(IOThemeContext);
return (
<Text
numberOfLines={1}
ellipsizeMode="tail"
style={{ fontSize: 9, color: IOColors[theme["textBody-tertiary"]] }}
>
{value}
</Text>
);
};

export const SpacerViewerBox = ({
size,
orientation = "vertical"
}: SpacerViewerBoxProps) => {
const theme = useContext(IOThemeContext);
return (
<>
{orientation === "vertical" ? (
<View style={{ flexDirection: "column" }}>
<View
style={{
backgroundColor: IOColors[theme["appBackground-tertiary"]]
}}
>
<VSpacer size={size} />
</View>
{size && (
<View style={{ flexDirection: "row", marginTop: 4 }}>
<SpacerLabel value={size} />
</View>
)}
</View>
) : (
<View style={{ flexDirection: "row" }}>
<View
style={{
backgroundColor: IOColors[theme["appBackground-tertiary"]],
height: 75
}}
>
<HSpacer size={size} />
</View>
{size && (
<View style={{ flexDirection: "column", marginLeft: 4 }}>
<SpacerLabel value={size} />
</View>
)}
</View>
)}
</>
);
};
14 changes: 11 additions & 3 deletions example/src/navigation/navigator.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createStackNavigator } from "@react-navigation/stack";
import React from "react";
import { Icons } from "../pages/Icons";
import { Logos } from "../pages/Logos";

import { DSAdvice } from "../pages/Advice";
import { DSAlert } from "../pages/Alert";
import { Icons } from "../pages/Icons";
import { Layout } from "../pages/Layout";
import { Logos } from "../pages/Logos";
import MainScreen from "../pages/MainScreen";
import { Pictograms } from "../pages/Pictograms";
import { Typography } from "../pages/Typography";
Expand Down Expand Up @@ -57,6 +57,14 @@ const AppNavigator = () => (
headerBackTitleVisible: false
}}
/>
<Stack.Screen
name={APP_ROUTES.FOUNDATION.LAYOUT.route}
component={Layout}
options={{
headerTitle: APP_ROUTES.FOUNDATION.LAYOUT.title,
headerBackTitleVisible: false
}}
/>
<Stack.Screen
name={APP_ROUTES.COMPONENTS.ADVICE.route}
component={DSAdvice}
Expand Down
164 changes: 164 additions & 0 deletions example/src/pages/Layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import {
Body,
ContentWrapper,
Divider,
H1,
H3,
HSpacer,
IOAppMargin,
IOColors,
IOSpacer,
IOThemeContext,
LabelSmall,
VDivider,
VSpacer
} from "@pagopa/io-app-design-system";
import React, { useContext } from "react";
import { View } from "react-native";
import { NoMarginScreen } from "../components/Screen";
import { SpacerViewerBox } from "../components/SpacerViewerBox";

export const Layout = () => {
const theme = useContext(IOThemeContext);

return (
<NoMarginScreen>
<ContentWrapper>
<H1
color={theme["textHeading-default"]}
weight={"Bold"}
style={{ marginBottom: 16 }}
>
Grid
</H1>
<H3
color={theme["textHeading-default"]}
weight={"SemiBold"}
style={{ marginBottom: 16 }}
>
ContentWrapper
</H3>
</ContentWrapper>
{IOAppMargin.map((value, i, arr) => (
<React.Fragment key={`${value}-${i}`}>
<View
style={{
backgroundColor: IOColors[theme["appBackground-tertiary"]]
}}
>
<ContentWrapper margin={value}>
<View
style={{
paddingVertical: 16,
backgroundColor: IOColors[theme["appBackground-secondary"]]
}}
>
<Body color={theme["textBody-secondary"]}>Content example</Body>
<LabelSmall
style={{ position: "absolute", right: 4, top: 4 }}
fontSize="small"
weight="Regular"
color={theme["textBody-tertiary"]}
>
{value}
</LabelSmall>
</View>
</ContentWrapper>
</View>
{i !== arr.length - 1 && <VSpacer size={16} />}
</React.Fragment>
))}

<VSpacer size={40} />

<ContentWrapper>
<H1
color={theme["textHeading-default"]}
weight={"Bold"}
style={{ marginBottom: 16 }}
>
Spacing
</H1>

<H3
color={theme["textHeading-default"]}
weight={"SemiBold"}
style={{ marginBottom: 16 }}
>
VSpacer
</H3>

{/* Vertical */}
{IOSpacer.map((spacerEntry, i, arr) => (
<React.Fragment key={`${spacerEntry}-${i}-vertical`}>
<SpacerViewerBox orientation="vertical" size={spacerEntry} />
{/* Don't add spacer to the last item. Quick and dirty
alternative to the Stack component.
https://stackoverflow.com/a/60975451 */}
{i !== arr.length - 1 && <VSpacer size={16} />}
</React.Fragment>
))}

<VSpacer size={24} />

<H3
color={theme["textHeading-default"]}
weight={"SemiBold"}
style={{ marginBottom: 16 }}
>
HSpacer
</H3>

{/* Horizontal */}
<View style={{ flexDirection: "row" }}>
{IOSpacer.map((spacerEntry, i, arr) => (
<React.Fragment key={`${spacerEntry}-${i}-horizontal`}>
<SpacerViewerBox orientation="horizontal" size={spacerEntry} />
{i !== arr.length - 1 && <HSpacer size={8} />}
</React.Fragment>
))}
</View>

<VSpacer size={48} />
</ContentWrapper>

<ContentWrapper>
<H1
color={theme["textHeading-default"]}
weight={"Bold"}
style={{ marginBottom: 16 }}
>
Divider
</H1>

<H3
color={theme["textHeading-default"]}
weight={"SemiBold"}
style={{ marginBottom: 16 }}
>
Default (Horizontal)
</H3>

<Divider />
<VSpacer size={48} />
</ContentWrapper>
<Divider />
<VSpacer size={48} />

<ContentWrapper>
<H3
color={theme["textHeading-default"]}
weight={"SemiBold"}
style={{ marginBottom: 16 }}
>
Vertical
</H3>

<View style={{ flexDirection: "row", height: 100 }}>
<VDivider />
</View>
<VSpacer size={48} />
</ContentWrapper>
</NoMarginScreen>
);
};