Skip to content

Commit f7616a8

Browse files
committed
remove need for google
1 parent ac5844e commit f7616a8

File tree

5 files changed

+1014
-101
lines changed

5 files changed

+1014
-101
lines changed

packages/app/src/app/pages/Sandbox/Editor/Workspace/Dependencies/AddFont/FontPicker/List.tsx

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,45 @@
11
import React, { FunctionComponent, useState, useMemo } from 'react';
2-
import { Font } from '@samuelmeuli/font-manager';
32
import { List, SearchFonts, FontLI, FontFamily, Arrow } from './elements';
3+
import { fonts } from './fonts';
44

55
type Props = {
6-
fonts: Font[];
76
onSelection: (e: any) => void;
87
activeFontFamily: string;
9-
expanded: boolean;
108
};
119

1210
export const FontList: FunctionComponent<Props> = ({
13-
fonts,
1411
onSelection,
1512
activeFontFamily,
16-
expanded,
1713
}) => {
1814
const [searchTerm, setSearchTerm] = useState('');
1915

2016
const updateSearch = (e: any) => setSearchTerm(e.target.value);
2117

22-
const getFontId = (fontFamily: string): string =>
23-
fontFamily.replace(/\s+/g, '-').toLowerCase();
24-
25-
const getFonts: Font[] = useMemo(
18+
const getFonts: string[] = useMemo(
2619
() =>
2720
fonts.filter(f =>
28-
f.family.toLowerCase().includes(searchTerm.trim().toLowerCase())
21+
f.toLowerCase().includes(searchTerm.trim().toLowerCase())
2922
),
30-
[fonts, searchTerm]
23+
[searchTerm]
3124
);
3225
return (
3326
<>
3427
<Arrow />
35-
<List expanded={expanded}>
28+
<List>
3629
<SearchFonts
3730
type="text"
3831
value={searchTerm}
3932
onChange={updateSearch}
4033
placeholder="Search Typefaces"
4134
/>
42-
{getFonts.map((font: Font) => (
35+
{getFonts.map((font: string) => (
4336
<FontLI
44-
key={font.family}
45-
onClick={onSelection}
46-
onKeyPress={onSelection}
37+
key={font}
38+
onClick={() => onSelection(font)}
39+
onKeyPress={() => onSelection(font)}
4740
>
48-
<FontFamily
49-
type="button"
50-
id={`font-button-${getFontId(font.family)}`}
51-
active={font.family === activeFontFamily}
52-
>
53-
{font.family}
41+
<FontFamily type="button" active={font === activeFontFamily}>
42+
{font}
5443
</FontFamily>
5544
</FontLI>
5645
))}

packages/app/src/app/pages/Sandbox/Editor/Workspace/Dependencies/AddFont/FontPicker/elements.ts

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
import styled, { css } from 'styled-components';
1+
import styled from 'styled-components';
22
import Color from 'color';
33

4+
const svg = props =>
5+
`data:image/svg+xml,%3Csvg width='7' height='4' viewBox='0 0 7 4' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M3.50007 4L1.27146e-07 1.35122e-07L7 -4.76837e-07L3.50007 4Z' fill='${
6+
props.theme.light ? 'black' : 'white'
7+
}'/%3E%3C/svg%3E%0A`;
8+
49
const makeDarker = ({ theme }) =>
510
Color(theme['input.background'])
611
.darken(theme.light ? 0.1 : 0.3)
@@ -80,13 +85,8 @@ export const List = styled.ul<{ expanded?: boolean }>`
8085
background-color: ${props => makeLighter(props)};
8186
width: 240px;
8287
z-index: 10;
83-
84-
${props =>
85-
props.expanded &&
86-
css`
87-
max-height: 130px;
88-
display: block;
89-
`}
88+
max-height: 130px;
89+
display: block;
9090
`;
9191

9292
export const SelectedFont = styled.button<{ done?: boolean }>`
@@ -105,23 +105,18 @@ export const SelectedFont = styled.button<{ done?: boolean }>`
105105
position: relative;
106106
box-sizing: border-box;
107107
outline: none;
108+
cursor: pointer;
108109
109-
${props =>
110-
props.done &&
111-
css`
112-
:after {
113-
content: '';
114-
background-image: url("${`data:image/svg+xml,%3Csvg width='7' height='4' viewBox='0 0 7 4' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M3.50007 4L1.27146e-07 1.35122e-07L7 -4.76837e-07L3.50007 4Z' fill='${
115-
props.theme.light ? 'black' : 'white'
116-
}'/%3E%3C/svg%3E%0A`}");
117-
width: 7px;
118-
height: 4px;
119-
position: absolute;
120-
right: 0.5rem;
121-
top: 50%;
122-
transform: translateY(-50%);
123-
}
124-
`}
110+
:after {
111+
content: '';
112+
background-image: url("${props => svg(props)}");
113+
width: 7px;
114+
height: 4px;
115+
position: absolute;
116+
right: 0.5rem;
117+
top: 50%;
118+
transform: translateY(-50%);
119+
}
125120
`;
126121

127122
export const Arrow = styled.div`

0 commit comments

Comments
 (0)