@fountain-ui/core 2.0.0-beta.4 → 2.0.0-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/build/commonjs/AppBar/AppBar.js +8 -13
  2. package/build/commonjs/AppBar/AppBar.js.map +1 -1
  3. package/build/commonjs/Paper/Paper.js +11 -3
  4. package/build/commonjs/Paper/Paper.js.map +1 -1
  5. package/build/commonjs/Paper/PaperStylesProvider.js +14 -0
  6. package/build/commonjs/Paper/PaperStylesProvider.js.map +1 -0
  7. package/build/commonjs/Paper/usePaperStyles.js +17 -0
  8. package/build/commonjs/Paper/usePaperStyles.js.map +1 -0
  9. package/build/commonjs/TextField/InputLabel.js +13 -7
  10. package/build/commonjs/TextField/InputLabel.js.map +1 -1
  11. package/build/commonjs/TextField/OutlinedTextField.js +0 -1
  12. package/build/commonjs/TextField/OutlinedTextField.js.map +1 -1
  13. package/build/commonjs/hooks/useCollapsibleAppBar.js +3 -5
  14. package/build/commonjs/hooks/useCollapsibleAppBar.js.map +1 -1
  15. package/build/commonjs/hooks/useFadeInAppBar.js +4 -6
  16. package/build/commonjs/hooks/useFadeInAppBar.js.map +1 -1
  17. package/build/module/AppBar/AppBar.js +8 -13
  18. package/build/module/AppBar/AppBar.js.map +1 -1
  19. package/build/module/Paper/Paper.js +10 -3
  20. package/build/module/Paper/Paper.js.map +1 -1
  21. package/build/module/Paper/PaperStylesProvider.js +4 -0
  22. package/build/module/Paper/PaperStylesProvider.js.map +1 -0
  23. package/build/module/Paper/usePaperStyles.js +7 -0
  24. package/build/module/Paper/usePaperStyles.js.map +1 -0
  25. package/build/module/TextField/InputLabel.js +12 -7
  26. package/build/module/TextField/InputLabel.js.map +1 -1
  27. package/build/module/TextField/OutlinedTextField.js +0 -1
  28. package/build/module/TextField/OutlinedTextField.js.map +1 -1
  29. package/build/module/hooks/useCollapsibleAppBar.js +3 -5
  30. package/build/module/hooks/useCollapsibleAppBar.js.map +1 -1
  31. package/build/module/hooks/useFadeInAppBar.js +4 -6
  32. package/build/module/hooks/useFadeInAppBar.js.map +1 -1
  33. package/build/typescript/AppBar/AppBarProps.d.ts +1 -1
  34. package/build/typescript/Paper/PaperProps.d.ts +5 -0
  35. package/build/typescript/Paper/PaperStylesProvider.d.ts +7 -0
  36. package/build/typescript/Paper/usePaperStyles.d.ts +1 -0
  37. package/build/typescript/hooks/useCollapsibleAppBar.d.ts +0 -1
  38. package/build/typescript/hooks/useFadeInAppBar.d.ts +0 -1
  39. package/package.json +3 -3
  40. package/src/AppBar/AppBar.tsx +13 -21
  41. package/src/AppBar/AppBarProps.ts +1 -1
  42. package/src/Paper/Paper.tsx +14 -8
  43. package/src/Paper/PaperProps.ts +6 -0
  44. package/src/Paper/PaperStylesProvider.tsx +9 -0
  45. package/src/Paper/usePaperStyles.ts +6 -0
  46. package/src/TextField/InputLabel.tsx +12 -5
  47. package/src/TextField/OutlinedTextField.tsx +1 -1
  48. package/src/hooks/useCollapsibleAppBar.ts +2 -4
  49. package/src/hooks/useFadeInAppBar.ts +1 -4
@@ -5,11 +5,7 @@ import Paper from '../Paper';
5
5
  import { css, useTheme } from '../styles';
6
6
  import type AppBarProps from './AppBarProps';
7
7
 
8
- type AppBarStyleKeys =
9
- | 'root'
10
- | 'colorDefault'
11
- | 'colorPrimary'
12
- | 'colorTransparent';
8
+ type AppBarStyleKeys = 'root';
13
9
 
14
10
  type AppBarStyles = NamedStylesStringUnion<AppBarStyleKeys>;
15
11
 
@@ -23,15 +19,6 @@ const useStyles: UseStyles<AppBarStyles> = function (): AppBarStyles {
23
19
  width: '100%',
24
20
  zIndex: theme.zIndex.appBar,
25
21
  },
26
- colorDefault: {
27
- backgroundColor: theme.palette.background.default,
28
- },
29
- colorPrimary: {
30
- backgroundColor: theme.palette.primary.main,
31
- },
32
- colorTransparent: {
33
- backgroundColor: 'transparent',
34
- },
35
22
  };
36
23
  };
37
24
 
@@ -42,26 +29,31 @@ const AppBar = React.forwardRef<View, AppBarProps>(function AppBar(props, ref) {
42
29
  ...otherProps
43
30
  } = props;
44
31
 
32
+ const theme = useTheme();
33
+
45
34
  const styles = useStyles();
46
35
 
47
- const colorStyle = color === 'default'
48
- ? styles.colorDefault
49
- : color === 'primary'
50
- ? styles.colorPrimary
51
- : styles.colorTransparent;
36
+ const backgroundColor = color === 'default'
37
+ ? theme.palette.background.default
38
+ : color === 'paper'
39
+ ? theme.palette.paper.default
40
+ : color === 'primary'
41
+ ? theme.palette.primary.main
42
+ : 'transparent';
52
43
 
53
44
  const paperStyle = css([
54
45
  styles.root,
55
- colorStyle,
46
+ { backgroundColor },
56
47
  style,
57
48
  ]);
58
49
 
59
50
  return (
60
51
  <Paper
61
52
  ref={ref}
62
- square
53
+ colorValue={backgroundColor}
63
54
  elevation={0}
64
55
  style={paperStyle}
56
+ square={true}
65
57
  {...otherProps}
66
58
  />
67
59
  );
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import type { OverridableComponentProps } from '../types';
3
3
  import type { PaperProps } from '../Paper';
4
4
 
5
- export type AppBarColor = 'default' | 'primary' | 'transparent';
5
+ export type AppBarColor = 'default' | 'paper' | 'primary' | 'transparent';
6
6
 
7
7
  export default interface AppBarProps extends OverridableComponentProps<PaperProps, {
8
8
  /**
@@ -3,10 +3,12 @@ import { View } from 'react-native';
3
3
  import { css, StyleSheet, useTheme } from '../styles';
4
4
  import { useElevationStyle } from '../hooks';
5
5
  import type PaperProps from './PaperProps';
6
+ import PaperStylesProvider from './PaperStylesProvider';
6
7
 
7
8
  const Paper = React.forwardRef<View, PaperProps>(function Paper(props, ref) {
8
9
  const {
9
10
  color = 'default',
11
+ colorValue,
10
12
  elevation = 1,
11
13
  style: styleProp,
12
14
  square = false,
@@ -16,9 +18,9 @@ const Paper = React.forwardRef<View, PaperProps>(function Paper(props, ref) {
16
18
 
17
19
  const theme = useTheme();
18
20
 
19
- const rootStyle = {
20
- backgroundColor: theme.palette.paper[color],
21
- };
21
+ const backgroundColor = colorValue ?? theme.palette.paper[color];
22
+
23
+ const rootStyle = { backgroundColor };
22
24
 
23
25
  const roundedStyle = {
24
26
  borderRadius: theme.shape.roundness,
@@ -40,11 +42,15 @@ const Paper = React.forwardRef<View, PaperProps>(function Paper(props, ref) {
40
42
  ]);
41
43
 
42
44
  return (
43
- <View
44
- ref={ref}
45
- style={style}
46
- {...otherProps}
47
- />
45
+ <PaperStylesProvider
46
+ value={{ backgroundColor }}
47
+ >
48
+ <View
49
+ ref={ref}
50
+ style={style}
51
+ {...otherProps}
52
+ />
53
+ </PaperStylesProvider>
48
54
  );
49
55
  });
50
56
 
@@ -19,6 +19,12 @@ export default interface PaperProps extends OverridableComponentProps<ViewProps,
19
19
  */
20
20
  color?: PaperColor;
21
21
 
22
+ /**
23
+ * The hex color value of Paper.
24
+ * It has higher priority than `color` prop.
25
+ */
26
+ colorValue?: string;
27
+
22
28
  /**
23
29
  * Shadow depth, corresponds to `dp` in the spec.
24
30
  * It accepts values between 0 and 24 inclusive.
@@ -0,0 +1,9 @@
1
+ import { createContext } from 'react';
2
+
3
+ export type PaperStyles = {
4
+ backgroundColor: string;
5
+ }
6
+
7
+ export const PaperStylesContext = createContext<PaperStyles | null>(null);
8
+
9
+ export default PaperStylesContext.Provider;
@@ -0,0 +1,6 @@
1
+ import { useContext } from 'react';
2
+ import { PaperStylesContext } from './PaperStylesProvider';
3
+
4
+ export default function usePaperStyles() {
5
+ return useContext(PaperStylesContext);
6
+ };
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { Animated, LayoutChangeEvent, StyleSheet } from 'react-native';
3
3
  import { NamedStylesStringUnion, UseStyles } from '@fountain-ui/styles';
4
4
  import { useTheme } from '../styles';
5
+ import usePaperStyles from '../Paper/usePaperStyles';
5
6
  import { inputPaddingHorizontal } from './utils';
6
7
 
7
8
  interface LabelProps {
@@ -30,8 +31,6 @@ interface LabelProps {
30
31
  type InputLabelStyles = NamedStylesStringUnion<'background' | 'backgroundText' | 'placeholder'>;
31
32
 
32
33
  const useStyles: UseStyles<InputLabelStyles> = function (): InputLabelStyles {
33
- const theme = useTheme();
34
-
35
34
  return {
36
35
  background: {
37
36
  position: 'absolute',
@@ -40,15 +39,13 @@ const useStyles: UseStyles<InputLabelStyles> = function (): InputLabelStyles {
40
39
  bottom: 0,
41
40
  right: 0,
42
41
  width: 8,
43
- height: 2,
44
- backgroundColor: theme.palette.background.default,
42
+ height: 4,
45
43
  },
46
44
  backgroundText: {
47
45
  position: 'absolute',
48
46
  left: 18,
49
47
  paddingHorizontal: 0,
50
48
  color: 'transparent',
51
- backgroundColor: theme.palette.background.default,
52
49
  },
53
50
  placeholder: {
54
51
  position: 'absolute',
@@ -81,8 +78,16 @@ const InputLabel = (props: LabelProps) => {
81
78
  value,
82
79
  } = props;
83
80
 
81
+ const theme = useTheme();
82
+
84
83
  const styles = useStyles();
85
84
 
85
+ const paperStyles = usePaperStyles();
86
+
87
+ const backgroundStyle = {
88
+ backgroundColor: paperStyles?.backgroundColor ?? theme.palette.background.default,
89
+ };
90
+
86
91
  const hasFocus = hasActiveOutline || value;
87
92
  const opacity = animatedLabel.interpolate({
88
93
  inputRange: [0, 1],
@@ -141,6 +146,7 @@ const InputLabel = (props: LabelProps) => {
141
146
  pointerEvents={'none'}
142
147
  style={[
143
148
  styles.background,
149
+ backgroundStyle,
144
150
  {
145
151
  opacity,
146
152
  transform: [
@@ -159,6 +165,7 @@ const InputLabel = (props: LabelProps) => {
159
165
  style={[
160
166
  styles.placeholder,
161
167
  styles.backgroundText,
168
+ backgroundStyle,
162
169
  labelStyle,
163
170
  {
164
171
  top: topPosition + 1,
@@ -34,7 +34,6 @@ const useStyles: UseStyles<OutlinedTextFieldStyles> = function (): OutlinedTextF
34
34
  left: 0,
35
35
  right: 0,
36
36
  bottom: 0,
37
- backgroundColor: theme.palette.background.default,
38
37
  borderRadius: theme.shape.roundness,
39
38
  },
40
39
  input: {
@@ -80,6 +79,7 @@ const OutlinedTextField = React.forwardRef<TextInput, OutlinedTextFieldProps>(fu
80
79
  } = props;
81
80
 
82
81
  const theme = useTheme();
82
+
83
83
  const styles = useStyles();
84
84
 
85
85
  const hasActiveOutline = focused || error;
@@ -23,7 +23,6 @@ export interface ContentInsets {
23
23
 
24
24
  export interface Options {
25
25
  keyboardDismissMode?: 'none' | 'on-drag';
26
- translucent?: boolean;
27
26
  }
28
27
 
29
28
  export interface CollapsibleAppBar {
@@ -37,7 +36,6 @@ export interface CollapsibleAppBar {
37
36
 
38
37
  const defaultOptions: Required<Options> = {
39
38
  keyboardDismissMode: 'none',
40
- translucent: false,
41
39
  };
42
40
 
43
41
  const ANIMATION_DURATION_MILLIS = 100;
@@ -45,7 +43,7 @@ const ANIMATION_DURATION_MILLIS = 100;
45
43
  const SUPPORTS_DRAG_DETECTION = Platform.OS !== 'web';
46
44
 
47
45
  export default function useCollapsibleAppBar(userOptions: Options = defaultOptions): CollapsibleAppBar {
48
- const { translucent, keyboardDismissMode }: Required<Options> = {
46
+ const { keyboardDismissMode }: Required<Options> = {
49
47
  ...defaultOptions,
50
48
  ...userOptions,
51
49
  };
@@ -180,7 +178,7 @@ export default function useCollapsibleAppBar(userOptions: Options = defaultOptio
180
178
 
181
179
  const appBarStyle = [
182
180
  animatedStyle,
183
- translucent ? { paddingTop: safeAreaInsets.top } : undefined,
181
+ { paddingTop: safeAreaInsets.top },
184
182
  hasCollapsible ? styles.floating : undefined,
185
183
  ];
186
184
 
@@ -18,7 +18,6 @@ export interface Options {
18
18
  fadeInEndY?: number | ((appBarHeight: number) => number);
19
19
  floating?: boolean;
20
20
  keyboardDismissMode?: 'none' | 'on-drag';
21
- translucent?: boolean;
22
21
  }
23
22
 
24
23
  export interface FadeInAppBar {
@@ -35,7 +34,6 @@ const defaultOptions: Required<Options> = {
35
34
  fadeInEndY: (appBarHeight) => appBarHeight,
36
35
  floating: true,
37
36
  keyboardDismissMode: 'none',
38
- translucent: false,
39
37
  };
40
38
 
41
39
  const shadowOffset = Platform.OS === 'ios' ? { width: 0, height: 3 } : undefined;
@@ -46,7 +44,6 @@ export default function useFadeInAppBar(userOptions: Options = defaultOptions):
46
44
  fadeInEndY,
47
45
  floating,
48
46
  keyboardDismissMode,
49
- translucent,
50
47
  }: Required<Options> = {
51
48
  ...defaultOptions,
52
49
  ...userOptions,
@@ -118,7 +115,7 @@ export default function useFadeInAppBar(userOptions: Options = defaultOptions):
118
115
 
119
116
  const appBarStyle = [
120
117
  animatedAppBarStyle,
121
- translucent ? { paddingTop: safeAreaInsets.top } : undefined,
118
+ { paddingTop: safeAreaInsets.top },
122
119
  floating ? styles.floating : undefined,
123
120
  ];
124
121