Skip to content

Commit 95f5e0f

Browse files
committed
Add examples of default-with-fork components
1 parent a91243f commit 95f5e0f

File tree

9 files changed

+184
-3
lines changed

9 files changed

+184
-3
lines changed

apps/example-ui/Button/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import * as React from 'react';
99
import { css, html } from 'react-strict-dom';
1010

1111
/**
12-
* Example of a shared button.
12+
* Example of a cross-platform button.
1313
*/
1414
export function Button(props) {
1515
return (
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import * as React from 'react';
9+
import { css, html } from 'react-strict-dom';
10+
11+
/**
12+
* Example of a cross-platform button.
13+
*/
14+
export function NativeForkButton(props) {
15+
return (
16+
<html.button style={styles.pressable}>
17+
<html.span style={styles.text}>{props.children}</html.span>
18+
<html.span style={styles.text}>(shared)</html.span>
19+
</html.button>
20+
);
21+
}
22+
23+
const styles = css.create({
24+
pressable: {
25+
alignSelf: 'flex-start',
26+
backgroundColor: 'darkgreen',
27+
borderBottomWidth: 1,
28+
borderBottomStyle: 'solid',
29+
display: 'flex',
30+
gap: '0.25rem',
31+
paddingBlock: 8,
32+
paddingInline: 32
33+
},
34+
text: {
35+
color: 'white',
36+
fontFamily: 'Arial',
37+
fontSize: 16,
38+
fontWeight: 'bold',
39+
textAlign: 'center'
40+
}
41+
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import * as React from 'react';
9+
import { Pressable, StyleSheet, Text } from 'react-native';
10+
11+
/**
12+
* Example of a native-fork, where the default is cross-platform.
13+
*/
14+
export function NativeForkButton(props) {
15+
return (
16+
<Pressable style={styles.pressable}>
17+
<Text style={styles.text}>{props.children} (native)</Text>
18+
</Pressable>
19+
);
20+
}
21+
22+
const styles = StyleSheet.create({
23+
pressable: {
24+
alignSelf: 'flex-start',
25+
backgroundColor: 'darkgreen',
26+
borderBottomWidth: 1,
27+
borderBottomStyle: 'solid',
28+
paddingBlock: 8,
29+
paddingInline: 32
30+
},
31+
text: {
32+
color: 'white',
33+
fontFamily: 'Arial',
34+
fontSize: 16,
35+
fontWeight: 'bold',
36+
textAlign: 'center'
37+
}
38+
});
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import * as React from 'react';
9+
import { css, html } from 'react-strict-dom';
10+
11+
/**
12+
* Example of a cross-platform button.
13+
*/
14+
export function WebForkButton(props) {
15+
return (
16+
<html.button style={styles.pressable}>
17+
<html.span style={styles.text}>{props.children}</html.span>
18+
<html.span style={styles.text}>(shared)</html.span>
19+
</html.button>
20+
);
21+
}
22+
23+
const styles = css.create({
24+
pressable: {
25+
alignSelf: 'flex-start',
26+
backgroundColor: 'darkgreen',
27+
borderBottomWidth: 1,
28+
borderBottomStyle: 'solid',
29+
display: 'flex',
30+
gap: '0.25rem',
31+
paddingBlock: 8,
32+
paddingInline: 32
33+
},
34+
text: {
35+
color: 'white',
36+
fontFamily: 'Arial',
37+
fontSize: 16,
38+
fontWeight: 'bold',
39+
textAlign: 'center'
40+
}
41+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import * as React from 'react';
9+
10+
/**
11+
* Example of a web-fork, where the default is cross-platform.
12+
*/
13+
export function WebForkButton(props) {
14+
return (
15+
<button style={styles.pressable} type="button">
16+
<span style={styles.text}>{props.children} (web)</span>
17+
</button>
18+
);
19+
}
20+
21+
const styles = {
22+
pressable: {
23+
backgroundColor: 'darkgreen',
24+
borderBottomWidth: 1,
25+
borderBottomStyle: 'solid',
26+
paddingBlock: 8,
27+
paddingInline: 32
28+
},
29+
text: {
30+
color: 'white',
31+
fontFamily: 'Arial',
32+
fontSize: 16,
33+
fontWeight: 'bold',
34+
textAlign: 'center'
35+
}
36+
};

apps/example-ui/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
// Examples of shared components
99
export { Button } from './Button';
1010

11+
// Examples of default shared with platform forks
12+
export { NativeForkButton } from './NativeForkButton';
13+
export { WebForkButton } from './WebForkButton';
14+
1115
// Examples of platform-specific component forks
1216
export { PlatformButton } from './PlatformButton';
1317
export { PlatformShell } from './PlatformShell';

apps/expo-app/src/components/App.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
*/
77

88
import * as React from 'react';
9-
import { Button, PlatformButton, PlatformShell } from 'example-ui';
9+
import {
10+
Button,
11+
NativeForkButton,
12+
PlatformButton,
13+
PlatformShell,
14+
WebForkButton
15+
} from 'example-ui';
1016
import { html } from 'react-strict-dom';
1117

1218
export default function App() {
@@ -16,6 +22,8 @@ export default function App() {
1622
<html.p>Hello</html.p>
1723
<Button>Button</Button>
1824
<PlatformButton>PlatformButton</PlatformButton>
25+
<NativeForkButton>NativeForkButton</NativeForkButton>
26+
<WebForkButton>WebForkButton</WebForkButton>
1927
</PlatformShell>
2028
</React.StrictMode>
2129
);

apps/expo-app/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"compilerOptions": {},
3+
"extends": "expo/tsconfig.base"
4+
}

apps/nextjs-app/src/app/page.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
18
import * as React from 'react';
2-
import { Button, PlatformButton, PlatformShell } from 'example-ui';
9+
import { Button, NativeForkButton, PlatformButton, PlatformShell, WebForkButton } from 'example-ui';
310
import { html } from 'react-strict-dom';
411

512
export default function App() {
@@ -9,6 +16,8 @@ export default function App() {
916
<html.p>Hello</html.p>
1017
<Button>Button</Button>
1118
<PlatformButton>PlatformButton</PlatformButton>
19+
<NativeForkButton>NativeForkButton</NativeForkButton>
20+
<WebForkButton>WebForkButton</WebForkButton>
1221
</PlatformShell>
1322
</React.StrictMode>
1423
);

0 commit comments

Comments
 (0)