axieinfinity / festival Goto Github PK
View Code? Open in Web Editor NEWDesign principles of a front-end system ๐
Design principles of a front-end system ๐
Can you guess what's the color of this without looking at browser:
<div className="bg-red bg-blue" />
It depends on CSS's definition order, which is not guaranteed by Tailwind (and that's a good thing).
What should be done is to be sure one type of attribute can only be set at most once. In other words, use JS or whatever to ensure there is only one "bg-foo" at the final result
When designing and using React components, we usually need to export and import more than just the component itself. For example, we may want to import the interface of a prop (e.g., button's color) or its implementations/options (e.g., the "primary" color for a button).
This page describes our expectations, several approaches, and what we believe is the optimal solution to export and import React components as JS modules (for now).
We should choose an approach that:
Although there are only 2 types of export in JavaScript (default and named), there are many ways (in term of syntax) to export and import from a module. Here we only discuss the most prominent ones:
// Button.ts
export interface Color { light: string; dark: string; }
export const Colors: { [key: string]: Color } = { /* ... */}
export const Component = ({ color: Color }) => (/* ... */);
// Foo.tsx
import * as Button from "@dvkndn/core/button";
import * as Tag from "@dvkndn/core/tag";
<Button.Component color={Button.Colors.Primary} />
// Button.ts
export interface ButtonColor { light: string; dark: string; }
export const ButtonColors: { [key: string]: Color } = { /* ... */ };
export const Button = ({ color: Color }) => (/* ... */);
// Foo.tsx
import { Button, ButtonColors } from "@dvkndn/core/button";
import { Tag, TagColors } from "@dvkndn/core/tag";
<Button color={ButtonColors.Primary} />
// Button.ts
export interface Color { light: string; dark: string; }
export const Colors: { [key: string]: Color } = { /* ... */ };
export default ({ color: Color }) => (/* ... */);
// C1. Alias import
// Foo.tsx
import Button, { Colors as ButtonColors } from "@dvkndn/core/button";
import Tag, { Colors as TagColors } from "@dvkndn/core/tag";
<Button color={ButtonColors.Primary} />
// C2. Namespace import
// Foo.tsx
import Button, * as button from "@dvkndn/core/button";
import Tag, * as tag from "@dvkndn/core/button";
<Button color={button.Colors.Primary} />
Button
button
but this is obviously not as good as Aimport { FooA, FooB, ..., FooX }
).Therefore, for now, we prefer the approach A.
Don't use @apply. They are unnecessarily complicated and can be solved easier with native solution: CSS variables. For example:
:root {
--color-red: #123456
}
to use in tailwinds:
red: "var(--color-red)",
to use outside of tailwind:
body {
color: var(--color-red);
}
Some components need to have a reference to a DOM element created by their consumers. For example, a Popover
component needs to know its target
's DOM element's position to render the content next to it:
We are going to consider 3 approaches:
<Popover content={<Content />}>
{(ref) => (
<Button ref={ref}>Click me</Button>
)}
</Popover>
Result:
<button>Click me</button>
Pros:
Cons:
span
and then ref to that span
element
<Popover content={<Content />}>
<Button ref={ref}>Click me</Button>
</Popover>
Result:
<span>
<button>Click me</button>
</span>
Pros:
Cons:
<Popover content={<Content />}>
<Button ref={ref}>Click me</Button>
</Popover>
<button>Click me</button>
Pros:
Cons:
How: Using ReactDOM.findElement().
On the Popover
case, I think Solution #3
is should fit the most, since it maintain the DOM order also the convenience for library user.
This is a valid usage, but can you guess what will be the background color of the Button:
<Button className="bg-success-4" type="danger" />
In general, inheriting class names, although common, is not a good practice. It allows consumers of Button to change Button's internal attributes (background, font size) while the author of Button would have no idea about this.
This is a burden, since the author may be limited in improving the Button, since they don't know what are all of the cases that may break.
In practice:
Web Styling (Draft)
document.tags.H1.fontSize = "20pt";
IDO dream
CSS is not designed to be a programming language
Because of component-based, actually
Portability
Dev exp
User exp
https://jxnblk.com/blog/why-you-should-learn-css-in-js/
https://mxstbr.com/thoughts/css-in-js/
https://noti.st/brucelawson/5O0d81#sQH4abT
https://csswizardry.com/2014/10/the-specificity-graph/
https://css-tricks.com/the-fragmented-but-evolving-state-of-css-in-js/
https://css-tricks.com/bridging-the-gap-between-css-and-javascript-css-modules-postcss-and-the-future-of-css/
https://css-tricks.com/the-differing-perspectives-on-css-in-js/
https://css-tricks.com/the-many-ways-to-include-css-in-javascript-applications/
10px vs 8px vs 12px
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.