Skip to content

Commit

Permalink
feat: add core components
Browse files Browse the repository at this point in the history
  • Loading branch information
felipprodrigues committed Oct 10, 2023
0 parents commit 47c6f74
Show file tree
Hide file tree
Showing 77 changed files with 26,042 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
.turbo
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Components

- [ ] Text
- [ ] Heading
- [ ] Box
- [ ] Button
- [ ] Textinput
- [ ] Textarea
- [ ] Checkbox
- [ ] Avatar
- [ ] Multistep
24,412 changes: 24,412 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"private": true,
"workspaces": [
"packages/*"
],
"scripts": {
"dev": "turbo run dev --parallel",
"build": "turbo run build"
},
"devDependencies": {
"turbo": "^1.10.14"
}
}
3 changes: 3 additions & 0 deletions packages/docs/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@far-ui/eslint-config"
}
26 changes: 26 additions & 0 deletions packages/docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

storybook-static

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
30 changes: 30 additions & 0 deletions packages/docs/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { StorybookConfig } from "@storybook/react-vite";

import { join, dirname } from "path";

/**
* This function is used to resolve the absolute path of a package.
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
*/
function getAbsolutePath(value: string): any {
return dirname(require.resolve(join(value, "package.json")));
}
const config: StorybookConfig = {
stories: ["../src/pages/**/*.stories.mdx", "../src/stories/**/*.stories.tsx"],
// docs/src/pages/home.stories.mdx
addons: [
getAbsolutePath("@storybook/addon-links"),
getAbsolutePath("@storybook/addon-essentials"),
getAbsolutePath("@storybook/addon-onboarding"),
getAbsolutePath("@storybook/addon-interactions"),
getAbsolutePath("@storybook/addon-a11y"),
],
framework: {
name: getAbsolutePath("@storybook/react-vite"),
options: {},
},
docs: {
autodocs: true,
},
};
export default config;
6 changes: 6 additions & 0 deletions packages/docs/.storybook/manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {addons} from '@storybook/manager-api'
import {themes} from '@storybook/theming'

addons.setConfig({
theme: themes.dark
})
7 changes: 7 additions & 0 deletions packages/docs/.storybook/preview-head.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<link rel="preconnect" href="https://fonts.googleapis.com"/>
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin/>
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;700&family=Roboto:wght@400;500;700&display=swap" rel="stylesheet" />

<script>
window.global = window;
</script>
22 changes: 22 additions & 0 deletions packages/docs/.storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { Preview } from "@storybook/react";
import { themes } from "@storybook/theming";

const preview: Preview = {
parameters: {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
backgrounds: {
default: "dark",
},
docs: {
theme: themes.dark,
},
},
};

export default preview;
27 changes: 27 additions & 0 deletions packages/docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
```

- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
13 changes: 13 additions & 0 deletions packages/docs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
50 changes: 50 additions & 0 deletions packages/docs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "@far-ui/docs",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "storybook dev -p 6006",
"deploy-storybook": "storybook-to-ghpages",
"build-vite": "tsc && vite build",
"build": "storybook build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"@far-ui/eslint-config": "*",
"@far-ui/react": "*",
"@far-ui/tokens": "*",
"@far-ui/ts-config": "*",
"@storybook/addon-a11y": "^7.4.6",
"@storybook/addon-docs": "^7.4.5",
"phosphor-react": "^1.4.1",
"polished": "^4.2.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@storybook/addon-essentials": "^7.4.5",
"@storybook/addon-interactions": "^7.4.5",
"@storybook/addon-links": "^7.4.5",
"@storybook/addon-onboarding": "^1.0.8",
"@storybook/blocks": "^7.4.5",
"@storybook/builder-vite": "^0.3.0",
"@storybook/react": "^7.4.5",
"@storybook/react-vite": "^7.4.5",
"@storybook/storybook-deployer": "^2.8.16",
"@storybook/testing-library": "^0.2.1",
"@types/react": "^18.2.15",
"@types/react-dom": "^18.2.7",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@vitejs/plugin-react": "^4.0.3",
"eslint": "^8.45.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
"eslint-plugin-storybook": "^0.6.14",
"storybook": "^7.4.5",
"typescript": "^5.0.2",
"vite": "^4.4.5"
}
}
1 change: 1 addition & 0 deletions packages/docs/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions packages/docs/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}

@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
}

.card {
padding: 2em;
}

.read-the-docs {
color: #888;
}
35 changes: 35 additions & 0 deletions packages/docs/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { useState } from 'react'
import reactLogo from './assets/react.svg'
import viteLogo from '/vite.svg'
import './App.css'

function App() {
const [count, setCount] = useState(0)

return (
<>
<div>
<a href="https://vitejs.dev" target="_blank">
<img src={viteLogo} className="logo" alt="Vite logo" />
</a>
<a href="https://react.dev" target="_blank">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
</div>
<h1>Vite + React</h1>
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>
count is {count}
</button>
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
</div>
<p className="read-the-docs">
Click on the Vite and React logos to learn more
</p>
</>
)
}

export default App
23 changes: 23 additions & 0 deletions packages/docs/src/components/ColorsGrid.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* eslint-disable prettier/prettier */
import { colors } from "@far-ui/tokens";
import { getContrast } from "polished";

export function ColorsGrid() {
return Object.entries(colors).map(([key, color]) => {
return (
<div key={key} style={{ backgroundColor: color, padding: "2rem" }}>
<div
style={{
display: "flex",
justifyContent: "space-between",
fontFamily: "monospace",
color: getContrast(color, "#fff") < 3.5 ? "#000" : "#fff",
}}
>
<strong>${key}</strong>
<span>{color}</span>
</div>
</div>
);
});
}
35 changes: 35 additions & 0 deletions packages/docs/src/components/TokensGrid.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* eslint-disable prettier/prettier */
import "../styles/tokens-grid.css";

interface TokensGridProps {
tokens: Record<string, string>;
hasRemValue?: boolean;
}

export function TokensGrid({ tokens, hasRemValue = false }: TokensGridProps) {
return (
<table className="tokens-grid">
<thead>
<tr>
<th>Name</th>
<th>Value</th>
{hasRemValue && <th>Pixels</th>}
</tr>
</thead>

<tbody>
{Object.entries(tokens).map(([key, value]) => {
return (
<tr key={key}>
<td>{key}</td>
<td>{value}</td>
{hasRemValue && (
<th>{Number(value.replace("rem", "") * 16)}px</th>
)}
</tr>
);
})}
</tbody>
</table>
);
}
Loading

0 comments on commit 47c6f74

Please sign in to comment.