refactor(app): switch to @phosphor-icons/core and format files
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import React from 'react';
|
||||
import { render } from '@testing-library/react';
|
||||
import App from './App';
|
||||
import React from "react";
|
||||
import { render } from "@testing-library/react";
|
||||
import App from "./App";
|
||||
|
||||
test('renders learn react link', () => {
|
||||
test("renders learn react link", () => {
|
||||
const { getByText } = render(<App />);
|
||||
const linkElement = getByText(/learn react/i);
|
||||
expect(linkElement).toBeInTheDocument();
|
||||
|
||||
@@ -5,13 +5,16 @@ interface ErrorBoundaryProps {
|
||||
}
|
||||
|
||||
interface ErrorBoundaryState {
|
||||
errorMessage?: string
|
||||
errorMessage?: string;
|
||||
}
|
||||
|
||||
export default class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
||||
export default class ErrorBoundary extends React.Component<
|
||||
ErrorBoundaryProps,
|
||||
ErrorBoundaryState
|
||||
> {
|
||||
constructor(props: any) {
|
||||
super(props);
|
||||
this.state = { errorMessage: "" }
|
||||
this.state = { errorMessage: "" };
|
||||
}
|
||||
|
||||
static getDerivedStateFromError(error: any) {
|
||||
|
||||
@@ -34,8 +34,8 @@ const Footer: React.FC<FooterProps> = () => {
|
||||
a little quirky, too.
|
||||
</p>
|
||||
<p>
|
||||
We're thankful for the tools we've benefited from and
|
||||
this is our contribution towards a collaborative community.
|
||||
We're thankful for the tools we've benefited from and this is our
|
||||
contribution towards a collaborative community.
|
||||
</p>
|
||||
<p>
|
||||
Phosphor is free and open-source, licensed under{" "}
|
||||
|
||||
@@ -11,7 +11,11 @@ interface NoticeProps {
|
||||
type?: "wait" | "help" | "warn" | "none";
|
||||
}
|
||||
|
||||
const Notice: React.FC<NoticeProps> = ({ message, type = "warn", children }) => {
|
||||
const Notice: React.FC<NoticeProps> = ({
|
||||
message,
|
||||
type = "warn",
|
||||
children,
|
||||
}) => {
|
||||
const isDark = useRecoilValue(isDarkThemeSelector);
|
||||
const query = useRecoilValue(searchQueryAtom);
|
||||
|
||||
|
||||
@@ -19,7 +19,8 @@ type SearchInputProps = {};
|
||||
const SearchInput: React.FC<SearchInputProps> = () => {
|
||||
const [value, setValue] = useState<string>("");
|
||||
const [query, setQuery] = useRecoilState(searchQueryAtom);
|
||||
const inputRef = useRef<HTMLInputElement>() as MutableRefObject<HTMLInputElement>;
|
||||
const inputRef =
|
||||
useRef<HTMLInputElement>() as MutableRefObject<HTMLInputElement>;
|
||||
|
||||
useHotkeys("ctrl+k,cmd+k", (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
@@ -2,9 +2,9 @@ import React, { useMemo } from "react";
|
||||
import { useRecoilState } from "recoil";
|
||||
import Select from "react-dropdown-select";
|
||||
import { PencilLine } from "phosphor-react";
|
||||
import { IconStyle } from "@phosphor-icons/core";
|
||||
|
||||
import { iconWeightAtom } from "../../state/atoms";
|
||||
import { IconStyle } from "../../lib";
|
||||
import "./StyleInput.css";
|
||||
|
||||
type WeightOption = { key: string; value: IconStyle; icon: JSX.Element };
|
||||
|
||||
@@ -2,8 +2,9 @@ import { useEffect } from "react";
|
||||
import { useSearchParam } from "react-use";
|
||||
import { useSetRecoilState } from "recoil";
|
||||
import TinyColor from "tinycolor2";
|
||||
import { IconStyle } from "@phosphor-icons/core";
|
||||
|
||||
import { iconColorAtom, iconWeightAtom, iconSizeAtom } from "../state/atoms";
|
||||
import { IconStyle } from "../lib";
|
||||
|
||||
export default () => {
|
||||
const weight = useSearchParam("weight")?.replace(/["']/g, "");
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
import { useState, useEffect } from "react";
|
||||
import { useTimeoutFn } from "react-use";
|
||||
|
||||
export default <T>(baseState: T, ms: number = 1000): [T, (transientValue: T) => void] => {
|
||||
export default <T>(
|
||||
baseState: T,
|
||||
ms: number = 1000
|
||||
): [T, (transientValue: T) => void] => {
|
||||
const [value, setValue] = useState<T>(baseState);
|
||||
const [, cancel, restart] = useTimeoutFn(() => setValue(baseState), ms);
|
||||
|
||||
|
||||
10360
src/lib/icons.ts
10360
src/lib/icons.ts
File diff suppressed because it is too large
Load Diff
@@ -1,34 +1,5 @@
|
||||
import { Icon } from "phosphor-react";
|
||||
|
||||
export enum IconStyle {
|
||||
THIN = "thin",
|
||||
LIGHT = "light",
|
||||
REGULAR = "regular",
|
||||
BOLD = "bold",
|
||||
FILL = "fill",
|
||||
DUOTONE = "duotone",
|
||||
}
|
||||
|
||||
export enum IconCategory {
|
||||
ARROWS = "arrows",
|
||||
BRAND = "brands",
|
||||
COMMERCE = "commerce",
|
||||
COMMUNICATION = "communications",
|
||||
DESIGN = "design",
|
||||
DEVELOPMENT = "technology & development",
|
||||
OFFICE = "office",
|
||||
EDITOR = "editor",
|
||||
FINANCE = "finances",
|
||||
GAMES = "games",
|
||||
HEALTH = "health & wellness",
|
||||
MAP = "maps & travel",
|
||||
MEDIA = "media",
|
||||
NATURE = "nature",
|
||||
OBJECTS = "objects",
|
||||
PEOPLE = "people",
|
||||
SYSTEM = "system",
|
||||
WEATHER = "weather",
|
||||
}
|
||||
import { IconCategory } from "@phosphor-icons/core";
|
||||
|
||||
export interface IconEntry {
|
||||
name: string;
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
// opt-in, read https://bit.ly/CRA-PWA
|
||||
|
||||
const isLocalhost = Boolean(
|
||||
window.location.hostname === 'localhost' ||
|
||||
window.location.hostname === "localhost" ||
|
||||
// [::1] is the IPv6 localhost address.
|
||||
window.location.hostname === '[::1]' ||
|
||||
window.location.hostname === "[::1]" ||
|
||||
// 127.0.0.0/8 are considered localhost for IPv4.
|
||||
window.location.hostname.match(
|
||||
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
|
||||
@@ -26,12 +26,9 @@ type Config = {
|
||||
};
|
||||
|
||||
export function register(config?: Config) {
|
||||
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
|
||||
if (process.env.NODE_ENV === "production" && "serviceWorker" in navigator) {
|
||||
// The URL constructor is available in all browsers that support SW.
|
||||
const publicUrl = new URL(
|
||||
process.env.PUBLIC_URL,
|
||||
window.location.href
|
||||
);
|
||||
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
|
||||
if (publicUrl.origin !== window.location.origin) {
|
||||
// Our service worker won't work if PUBLIC_URL is on a different origin
|
||||
// from what our page is served on. This might happen if a CDN is used to
|
||||
@@ -39,7 +36,7 @@ export function register(config?: Config) {
|
||||
return;
|
||||
}
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
window.addEventListener("load", () => {
|
||||
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
|
||||
|
||||
if (isLocalhost) {
|
||||
@@ -50,8 +47,8 @@ export function register(config?: Config) {
|
||||
// service worker/PWA documentation.
|
||||
navigator.serviceWorker.ready.then(() => {
|
||||
console.log(
|
||||
'This web app is being served cache-first by a service ' +
|
||||
'worker. To learn more, visit https://bit.ly/CRA-PWA'
|
||||
"This web app is being served cache-first by a service " +
|
||||
"worker. To learn more, visit https://bit.ly/CRA-PWA"
|
||||
);
|
||||
});
|
||||
} else {
|
||||
@@ -65,21 +62,21 @@ export function register(config?: Config) {
|
||||
function registerValidSW(swUrl: string, config?: Config) {
|
||||
navigator.serviceWorker
|
||||
.register(swUrl)
|
||||
.then(registration => {
|
||||
.then((registration) => {
|
||||
registration.onupdatefound = () => {
|
||||
const installingWorker = registration.installing;
|
||||
if (installingWorker == null) {
|
||||
return;
|
||||
}
|
||||
installingWorker.onstatechange = () => {
|
||||
if (installingWorker.state === 'installed') {
|
||||
if (installingWorker.state === "installed") {
|
||||
if (navigator.serviceWorker.controller) {
|
||||
// At this point, the updated precached content has been fetched,
|
||||
// but the previous service worker will still serve the older
|
||||
// content until all client tabs are closed.
|
||||
console.log(
|
||||
'New content is available and will be used when all ' +
|
||||
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
|
||||
"New content is available and will be used when all " +
|
||||
"tabs for this page are closed. See https://bit.ly/CRA-PWA."
|
||||
);
|
||||
|
||||
// Execute callback
|
||||
@@ -90,7 +87,7 @@ function registerValidSW(swUrl: string, config?: Config) {
|
||||
// At this point, everything has been precached.
|
||||
// It's the perfect time to display a
|
||||
// "Content is cached for offline use." message.
|
||||
console.log('Content is cached for offline use.');
|
||||
console.log("Content is cached for offline use.");
|
||||
|
||||
// Execute callback
|
||||
if (config && config.onSuccess) {
|
||||
@@ -101,25 +98,25 @@ function registerValidSW(swUrl: string, config?: Config) {
|
||||
};
|
||||
};
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error during service worker registration:', error);
|
||||
.catch((error) => {
|
||||
console.error("Error during service worker registration:", error);
|
||||
});
|
||||
}
|
||||
|
||||
function checkValidServiceWorker(swUrl: string, config?: Config) {
|
||||
// Check if the service worker can be found. If it can't reload the page.
|
||||
fetch(swUrl, {
|
||||
headers: { 'Service-Worker': 'script' }
|
||||
headers: { "Service-Worker": "script" },
|
||||
})
|
||||
.then(response => {
|
||||
.then((response) => {
|
||||
// Ensure service worker exists, and that we really are getting a JS file.
|
||||
const contentType = response.headers.get('content-type');
|
||||
const contentType = response.headers.get("content-type");
|
||||
if (
|
||||
response.status === 404 ||
|
||||
(contentType != null && contentType.indexOf('javascript') === -1)
|
||||
(contentType != null && contentType.indexOf("javascript") === -1)
|
||||
) {
|
||||
// No service worker found. Probably a different app. Reload the page.
|
||||
navigator.serviceWorker.ready.then(registration => {
|
||||
navigator.serviceWorker.ready.then((registration) => {
|
||||
registration.unregister().then(() => {
|
||||
window.location.reload();
|
||||
});
|
||||
@@ -131,18 +128,18 @@ function checkValidServiceWorker(swUrl: string, config?: Config) {
|
||||
})
|
||||
.catch(() => {
|
||||
console.log(
|
||||
'No internet connection found. App is running in offline mode.'
|
||||
"No internet connection found. App is running in offline mode."
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function unregister() {
|
||||
if ('serviceWorker' in navigator) {
|
||||
if ("serviceWorker" in navigator) {
|
||||
navigator.serviceWorker.ready
|
||||
.then(registration => {
|
||||
.then((registration) => {
|
||||
registration.unregister();
|
||||
})
|
||||
.catch(error => {
|
||||
.catch((error) => {
|
||||
console.error(error.message);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
// allows you to do things like:
|
||||
// expect(element).toHaveTextContent(/react/i)
|
||||
// learn more: https://github.com/testing-library/jest-dom
|
||||
import '@testing-library/jest-dom/extend-expect';
|
||||
import "@testing-library/jest-dom/extend-expect";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { atom } from "recoil";
|
||||
import { IconStyle } from "../lib";
|
||||
import { IconStyle } from "@phosphor-icons/core";
|
||||
|
||||
export const searchQueryAtom = atom<string>({
|
||||
key: "searchQueryAtom",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { selector, selectorFamily } from "recoil";
|
||||
import TinyColor from "tinycolor2";
|
||||
import Fuse from "fuse.js";
|
||||
import { IconCategory } from "@phosphor-icons/core";
|
||||
|
||||
import {
|
||||
searchQueryAtom,
|
||||
@@ -8,7 +9,7 @@ import {
|
||||
iconSizeAtom,
|
||||
iconColorAtom,
|
||||
} from "./atoms";
|
||||
import { IconEntry, IconCategory } from "../lib";
|
||||
import { IconEntry } from "../lib";
|
||||
import { icons } from "../lib/icons";
|
||||
|
||||
const fuse = new Fuse(icons, {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { SnippetType, IconStyle } from "../lib";
|
||||
import { IconStyle } from "@phosphor-icons/core";
|
||||
|
||||
import { SnippetType } from "../lib";
|
||||
|
||||
export function getCodeSnippets({
|
||||
name,
|
||||
|
||||
Reference in New Issue
Block a user