Skip to content

Commit c86ed5f

Browse files
committed
finish initial refactor, cleanup styleguide
1 parent e9fac98 commit c86ed5f

6 files changed

Lines changed: 44 additions & 153 deletions

File tree

common/styleguide.tsx

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -25,49 +25,7 @@ export function useLayout() {
2525
};
2626
}
2727

28-
export const colors = {
29-
primary: '#61DAFB',
30-
primaryLight: '#c1f4ff',
31-
primaryDark: '#39BEE2',
32-
primaryHover: '#61dafb16',
33-
sky: '#C6EEFB',
34-
powder: '#EEFAFE',
35-
pewter: '#BEC8CB',
36-
gray1: '#f9f9f9',
37-
gray2: '#ececec',
38-
gray3: '#CFCFD5',
39-
gray4: '#828898',
40-
gray5: '#505461',
41-
gray6: '#24262e',
42-
gray7: '#21232A',
43-
black: '#242424',
44-
white: '#ffffff',
45-
secondary: '#afb1af',
46-
warning: '#FBE679',
47-
warningLight: '#FEF7D6',
48-
warningDark: '#995e00',
49-
error: '#ff5555',
50-
success: '#4caf50',
51-
};
52-
53-
export const darkColors = {
54-
black: '#000',
55-
background: '#19191f',
56-
subHeader: '#14141a',
57-
border: '#2a2e36',
58-
veryDark: '#111114',
59-
dark: '#14141a',
60-
darkBright: '#1c1c21',
61-
powder: '#262a36',
62-
pewter: '#767C8E',
63-
secondary: '#a2a7ab',
64-
warningLight: '#2f2704',
65-
warning: '#9a810c',
66-
primaryDark: '#2e9ab8',
67-
};
68-
6928
const baseTextStyles = {
70-
color: colors.black,
7129
marginVertical: 0,
7230
fontWeight: '400' as const,
7331
fontFamily: 'inherit',

components/Library/DirectoryScore.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { View } from 'react-native';
1+
import { type ColorValue, View } from 'react-native';
22
import { Svg, Path, Circle } from 'react-native-svg';
33

4-
import { colors } from '~/common/styleguide';
54
import { type LibraryType } from '~/types';
65
import { MAX_SCORE } from '~/util/scoring';
76
import tw from '~/util/tailwind';
@@ -18,7 +17,9 @@ export function DirectoryScore({ score, matchingScoreModifiers, sizeMultiplier =
1817
const chunk = (MAX_SCORE - 5) / 5;
1918

2019
function getFill(chunkNumber = 1) {
21-
return score >= chunk * chunkNumber ? colors.primaryDark : 'currentColor';
20+
return score >= chunk * chunkNumber
21+
? (tw`text-primary-dark`.color as ColorValue)
22+
: 'currentColor';
2223
}
2324

2425
const scoreSymbol = (
@@ -30,7 +31,7 @@ export function DirectoryScore({ score, matchingScoreModifiers, sizeMultiplier =
3031
aria-label={`Score: ${score} out of 100`}>
3132
<Path
3233
d="M16.3789 5.76173C15.121 5.48057 14.2348 5.38423 13.3789 5.29298C12.8203 4.43746 12.0547 3.58199 11.4922 2.92966C12.5273 1.88672 14.8061 0.125596 15.9998 0.932227C17.1682 1.72171 16.7109 4.50782 16.3789 5.76173Z"
33-
fill={score > 0 ? colors.primaryDark : 'currentColor'}
34+
fill={score > 0 ? (tw`text-primary-dark`.color as ColorValue) : 'currentColor'}
3435
/>
3536
<Path
3637
d="M17.0621 12.5824C16.6766 11.3525 16.3169 10.5368 15.968 9.74996C16.4296 8.83845 16.7877 7.74766 17.0713 6.93436C18.4921 7.30936 21.1567 8.40227 21.055 9.83938C20.9555 11.2459 18.314 12.243 17.0621 12.5824Z"
@@ -52,7 +53,12 @@ export function DirectoryScore({ score, matchingScoreModifiers, sizeMultiplier =
5253
d="M10.1285 2.94207C9.25607 3.89083 8.7295 4.61021 8.22255 5.30577C7.20235 5.36177 6.07868 5.59709 5.23249 5.75806C4.84686 4.34012 4.46106 1.48608 5.75649 0.8556C7.02437 0.238523 9.2086 2.02757 10.1285 2.94207Z"
5354
fill={getFill(5)}
5455
/>
55-
<Circle cx="10.8074" cy="9.75731" r="1.98916" fill={colors.primaryDark} />
56+
<Circle
57+
cx="10.8074"
58+
cy="9.75731"
59+
r="1.98916"
60+
fill={tw`text-primary-dark`.color as ColorValue}
61+
/>
5662
</Svg>
5763
);
5864

components/Library/Thumbnail.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import * as HoverCard from '@radix-ui/react-hover-card';
22
import { memo, useState } from 'react';
3-
import { ActivityIndicator, useWindowDimensions, View } from 'react-native';
3+
import { ActivityIndicator, type ColorValue, useWindowDimensions, View } from 'react-native';
44

5-
import { colors } from '~/common/styleguide';
65
import tw from '~/util/tailwind';
76

87
import { Thumbnail as ThumbnailIcon } from '../Icons';
@@ -32,7 +31,7 @@ function Thumbnail({ url }: Props) {
3231
style={tw`mr-2.5 my-1 p-1.5 pb-0 min-h-7.5 box-border overflow-hidden text-center rounded border border-palette-gray2 dark:border-default`}>
3332
{showPreview && !isLoaded ? (
3433
<div style={tw`w-3.5 mx-px -mt-0.5`}>
35-
<ActivityIndicator size="small" color={colors.primaryDark} />
34+
<ActivityIndicator size="small" color={tw`text-primary-dark`.color as ColorValue} />
3635
</div>
3736
) : (
3837
<ThumbnailIcon

components/Search.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { useRouter } from 'next/router';
22
import { useEffect, useMemo, useRef, useState } from 'react';
3-
import { TextInput, View } from 'react-native';
3+
import { type ColorValue, TextInput, View } from 'react-native';
44
import { useDebouncedCallback } from 'use-debounce';
55

6-
import { colors, P, useLayout, Label } from '~/common/styleguide';
6+
import { P, useLayout, Label } from '~/common/styleguide';
77
import { type Query } from '~/types';
88
import isAppleDevice from '~/util/isAppleDevice';
99
import tw from '~/util/tailwind';
@@ -102,7 +102,7 @@ export default function Search({ query, total }: Props) {
102102
placeholder="Search libraries..."
103103
style={tw`flex flex-1 h-12.5 p-4 pl-11 font-sans text-xl text-white rounded-md -outline-offset-2 border-2 border-palette-gray5 dark:border-default`}
104104
defaultValue={search}
105-
placeholderTextColor={colors.gray4}
105+
placeholderTextColor={tw`text-palette-gray4`.color as ColorValue}
106106
/>
107107
{!isSmallScreen && (
108108
<View style={tw`absolute right-4 pointer-events-none flex-row gap-1 items-center`}>

context/CustomAppearanceProvider.tsx

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import AsyncStorage from '@react-native-async-storage/async-storage';
22
import { type PropsWithChildren, useEffect, useState } from 'react';
3-
import { View } from 'react-native';
43

54
import tw, { useDeviceContext, useAppColorScheme } from '~/util/tailwind';
65

@@ -16,7 +15,6 @@ const defaultState = { isDark: false };
1615
export default function CustomAppearanceProvider({ children }: PropsWithChildren) {
1716
const [colorScheme, , setColorScheme] = useAppColorScheme(tw);
1817
const [isDark, setIsDark] = useState(colorScheme === 'dark');
19-
const [isLoaded, setLoaded] = useState(false);
2018

2119
function toggleTheme(isDark: boolean) {
2220
const el = document.documentElement;
@@ -42,29 +40,24 @@ export default function CustomAppearanceProvider({ children }: PropsWithChildren
4240
const { isDark } = await rehydrateAppearanceState();
4341
toggleTheme(isDark);
4442
} catch {}
45-
setLoaded(true);
4643
}
4744

4845
void rehydrateAsync();
4946
}, []);
5047

51-
if (!isLoaded) {
52-
return <View />;
53-
} else {
54-
return (
55-
<CustomAppearanceContext.Provider
56-
key={tw.memoBuster}
57-
value={{
58-
isDark,
59-
setIsDark: isDark => {
60-
toggleTheme(isDark);
61-
void cacheAppearanceState({ isDark });
62-
},
63-
}}>
64-
{children}
65-
</CustomAppearanceContext.Provider>
66-
);
67-
}
48+
return (
49+
<CustomAppearanceContext.Provider
50+
key={tw.memoBuster}
51+
value={{
52+
isDark,
53+
setIsDark: isDark => {
54+
toggleTheme(isDark);
55+
void cacheAppearanceState({ isDark });
56+
},
57+
}}>
58+
{children}
59+
</CustomAppearanceContext.Provider>
60+
);
6861
}
6962

7063
async function cacheAppearanceState(appearance: Omit<CustomAppearanceContextType, 'setIsDark'>) {

scenes/PackageScoreScene.tsx

Lines changed: 15 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
import { useContext, useMemo } from 'react';
2-
import { StyleSheet, View } from 'react-native';
1+
import { useMemo } from 'react';
2+
import { View } from 'react-native';
33

4-
import { A, Caption, colors, darkColors, H6, useLayout } from '~/common/styleguide';
4+
import { A, Caption, H6, useLayout } from '~/common/styleguide';
55
import ContentContainer from '~/components/ContentContainer';
66
import { DirectoryScore } from '~/components/Library/DirectoryScore';
77
import DetailsNavigation from '~/components/Package/DetailsNavigation';
88
import NotFound from '~/components/Package/NotFound';
99
import PackageHeader from '~/components/Package/PackageHeader';
1010
import PageMeta from '~/components/PageMeta';
1111
import { ScoringCriterion } from '~/components/Score/ScoringCriterion';
12-
import CustomAppearanceContext from '~/context/CustomAppearanceContext';
1312
import { type PackageScorePageProps } from '~/types/pages';
1413
import { SCORING_CRITERIONS } from '~/util/scoring';
1514
import tw from '~/util/tailwind';
1615

1716
export default function PackageScoreScene({ apiData, packageName }: PackageScorePageProps) {
18-
const { isDark } = useContext(CustomAppearanceContext);
1917
const { isSmallScreen } = useLayout();
2018

2119
const library = useMemo(
@@ -27,14 +25,6 @@ export default function PackageScoreScene({ apiData, packageName }: PackageScore
2725
return <NotFound />;
2826
}
2927

30-
const scoreBoxBorderColor = isDark ? darkColors.border : colors.gray3;
31-
const headerColorStyle = {
32-
color: isDark ? darkColors.secondary : colors.gray5,
33-
};
34-
const secondaryColorStyle = {
35-
color: isDark ? colors.gray4 : colors.gray5,
36-
};
37-
3828
return (
3929
<>
4030
<PageMeta
@@ -48,45 +38,36 @@ export default function PackageScoreScene({ apiData, packageName }: PackageScore
4838
<PackageHeader library={library} />
4939
<View
5040
style={[
51-
styles.scoreBox,
52-
isSmallScreen && styles.scoreBoxSmall,
53-
{
54-
borderColor: scoreBoxBorderColor,
55-
backgroundColor: isDark ? colors.gray7 : colors.gray1,
56-
},
41+
tw`items-center flex-row gap-1 mt-2 mb-3 py-4 px-7 border rounded-xl border-palette-gray3 bg-palette-gray1 dark:bg-palette-gray7 dark:border-default`,
42+
isSmallScreen && tw`flex-col px-5`,
5743
]}>
5844
<View style={tw`items-center`}>
59-
<H6 style={styles.sectionHeader}>Directory score</H6>
45+
<H6 style={tw`mb-3`}>Directory score</H6>
6046
<DirectoryScore score={library.score} sizeMultiplier={2} />
61-
<span
62-
style={{
63-
...styles.scoreIndicator,
64-
color: isDark ? darkColors.primaryDark : colors.primaryDark,
65-
}}>
47+
<span style={tw`flex text-[24px] font-semibold items-center mt-1 text-primary-dark`}>
6648
{library.score}/100
6749
</span>
6850
</View>
6951
<View
7052
style={[
71-
styles.separator,
72-
isSmallScreen && styles.separatorSmall,
73-
{ backgroundColor: scoreBoxBorderColor },
53+
tw`w-[0.5px] min-h-[112px] mx-7 bg-palette-gray3 dark:bg-dark-brighter`,
54+
isSmallScreen && tw`w-full min-h-[0.5px] mx-0 my-3`,
7455
]}
7556
/>
7657
<View style={tw`flex flex-shrink gap-2`}>
77-
<Caption style={[tw`font-light`, secondaryColorStyle]}>
58+
<Caption style={tw`font-light text-palette-gray5 dark:text-palette-gray4`}>
7859
The Directory Score is the combination of multiple factors that relate to the
7960
quality of a library. A library can earn value by exhibiting &quot;good behavior
8061
criteria&quot; and can lose value by exhibiting &quot;bad behavior criteria&quot;.
8162
</Caption>
82-
<Caption style={[tw`font-light`, secondaryColorStyle]}>
63+
<Caption style={tw`font-light text-palette-gray5 dark:text-palette-gray4`}>
8364
Scores are subjective and are based on data that's readily available on GitHub and
8465
npm. They are not a perfect scores and may not reflect quality for your specific
8566
needs. <A href="/scoring">Read more</A>.
8667
</Caption>
8768
</View>
8869
</View>
89-
<H6 style={headerColorStyle}>Matching criteria</H6>
70+
<H6 style={tw`text-palette-gray5 dark:text-secondary`}>Matching criteria</H6>
9071
<View>
9172
{SCORING_CRITERIONS.filter(({ name }) =>
9273
library.matchingScoreModifiers.includes(name)
@@ -96,7 +77,7 @@ export default function PackageScoreScene({ apiData, packageName }: PackageScore
9677
</ScoringCriterion>
9778
))}
9879
</View>
99-
<H6 style={headerColorStyle}>Not matched criteria</H6>
80+
<H6 style={tw`text-palette-gray5 dark:text-secondary`}>Not matched criteria</H6>
10081
<View>
10182
{SCORING_CRITERIONS.filter(
10283
({ name }) => !library.matchingScoreModifiers.includes(name)
@@ -105,7 +86,8 @@ export default function PackageScoreScene({ apiData, packageName }: PackageScore
10586
headline={name}
10687
score={value}
10788
key={`unmatch-${name}`}
108-
style={styles.unmatchedCriterion}>
89+
// TODO: add PR with RN filters
90+
style={tw`opacity-60 border-2 border-dashed grayscale`}>
10991
{description}
11092
</ScoringCriterion>
11193
))}
@@ -115,50 +97,3 @@ export default function PackageScoreScene({ apiData, packageName }: PackageScore
11597
</>
11698
);
11799
}
118-
119-
const styles = StyleSheet.create({
120-
scoreBox: {
121-
display: 'flex',
122-
alignItems: 'center',
123-
flexDirection: 'row',
124-
gap: 4,
125-
marginTop: 8,
126-
marginBottom: 12,
127-
paddingVertical: 16,
128-
paddingHorizontal: 28,
129-
borderWidth: 1,
130-
borderStyle: 'solid',
131-
borderRadius: 12,
132-
},
133-
scoreBoxSmall: {
134-
flexDirection: 'column',
135-
paddingHorizontal: 20,
136-
},
137-
sectionHeader: {
138-
marginBottom: 12,
139-
},
140-
scoreIndicator: {
141-
display: 'flex',
142-
fontSize: 24,
143-
fontWeight: 600,
144-
alignItems: 'center',
145-
marginTop: 4,
146-
},
147-
separator: {
148-
width: 0.5,
149-
minHeight: 112,
150-
marginHorizontal: 28,
151-
},
152-
separatorSmall: {
153-
width: '100%',
154-
minHeight: 0.5,
155-
marginHorizontal: 0,
156-
marginVertical: 12,
157-
},
158-
unmatchedCriterion: {
159-
filter: 'grayscale(1)',
160-
opacity: 0.6,
161-
borderStyle: 'dashed',
162-
borderWidth: 2,
163-
},
164-
});

0 commit comments

Comments
 (0)