Skip to content

Commit

Permalink
feat: documentation improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mauroerta committed Jun 29, 2021
1 parent 7112169 commit 4ad3b5d
Show file tree
Hide file tree
Showing 32 changed files with 775 additions and 239 deletions.
104 changes: 23 additions & 81 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<div align="center">
<h1>morfeo</h1>
</div>
<a href="https://morfeo.dev">morfeo</a> is a framework-agnostic set of tools that will help you to build your next <strong>design system</strong> based on a single source of truth: the <strong>theme</strong>.
![Morfeo logo](https://morfeo.dev/img/morfeo.png)

[morfeo](https://morfeo.dev) is a framework-agnostic set of tools that will help you to build your next <strong>design system</strong> based on a single source of truth: the **theme**.

---

Expand All @@ -14,84 +13,23 @@

---

> :warning: ​We are working to optimize the packages and make the documentation clear and complete. :warning:
>
> Soon we'll provide documentation for each package, sandboxes with use cases, and a website full of articles.
> If you want to start using morfeo we'll love to have your feedback, feel free to contribute by opening a pull request or just sending some love in our slack chat.
---

<div align="center">
<a href="https://morfeo.dev">Documentation</a> |
<a href="https://github.com/VLK-STUDIO/morfeo">API</a> |
<a href="https://github.com/VLK-STUDIO/morfeo/blob/main/CONTRIBUTING.md">Contributing</a> |
<a href="https://morfeo.slack.com">Slack</a>
</div>
[Documentation](https://morfeo.dev) | [API](https://github.com/VLK-STUDIO/morfeo) | [Contributing](https://github.com/VLK-STUDIO/morfeo/blob/main/CONTRIBUTING.md) | [Slack](https://morfeo.slack.com)

---

You can use it with any framework like [React](https://reactjs.org/), [React Native](https://reactnative.dev/), [Vue](https://v3.vuejs.org/), [Angular](https://angular.io/), [Svelte](https://svelte.dev/) or just Vanilla JS/TS.

In other words, morfeo will transform this:

```typescript
{
componentName: 'Button',
variant: 'primary',
}
```

into this:

```typescript
{
color: '#e3e3e3',
backgroundColor: '#fff',
borderRadius: '20px',
'&:hover': {
opacity: 0.4,
},
}
```

Or, into a plain css:

```css
.button-primary {
color: #e3e3e3;
background-color: #fff;
border-radius: 20px;
}

.button-primary:hover {
opacity: 0.4;
}
```

By using a bit of magic explained [here](#how-it-works)

morfeo is cross-framework, but to have a faster implementation and a better developer experience we create a set of packages that integrates morfeo with the most used frameworks like:

**[@morfeo/react](https://www.npmjs.com/package/@morfeo/react)** made for React :atom_symbol:

**[@morfeo/native](https://www.npmjs.com/package/@morfeo/native)** perfect for React native :calling::atom_symbol:

**[@morfeo/svelte](https://www.npmjs.com/package/@morfeo/svelte)** matches perfectly with svelte :fire:

**[@morfeo/styled-components-web](https://www.npmjs.com/package/@morfeo/styled-components-web)** deep integration with styled-components :nail_care:
Morfeo it's a tool to build design systems based on a theme.

**@morfeo/angular** **_coming soon_**
It helps you to _follow a design language_ and write consistent UIs, whatever it is the framework of your choice.

**[@morfeo/jss](https://www.npmjs.com/package/@morfeo/jss)** will generate plain css from _css-in-js_
It's easy to use and, with the **browser extension**, your theme and your components are automatically documented.

## Motivations

When your application starts to grow, maintain UI consistency it's not easy.
Even in popular applications we often face **wrong typographies**, different **color pallettes** used across different pages or inconsistent **spacings** in each component.

These problems are even more frequent in large applications where different teams works on different features (maybe with different technologies and frameworks).
## Features

**morfeo** solves this problem by sharing across all the application a customizable `theme` that contains the "language" of the application design and a `parser` that generate styles based on this language, in this way the UIs an the components are always consistent.
- [Framework Agnostic](https://morfeo.dev/docs/Introduction/framework-agnostic)
- [Single source of truth](https://morfeo.dev/docs/Introduction/single-source-of-truth)
- [Dev Tool](https://morfeo.dev/docs/Introduction/dev-tool)
- [Extendible](https://morfeo.dev/docs/Introduction/extendible)
- [Easy to test](https://morfeo.dev/docs/Introduction/easy-to-testhttps://morfeo.dev/docs/Introduction/easy-to-test)

## How it works

Expand Down Expand Up @@ -143,7 +81,7 @@ Once you have a centralized theme, you need to parse this theme to generate the
This is an example with React

```tsx
import { theme, parsers } from '@morfeo/core';
import { parsers } from '@morfeo/core';

function Button() {
const style = parsers.resolve({ componentName: 'Button' });
Expand All @@ -152,11 +90,10 @@ function Button() {
}
```

Or if you want, you can use the hooks inside the package `@morfeo/hooks`
In the case of `React`, we built a package that suites it better: [@morfeo/react](../Packages/react)

```tsx
import { theme } from '@morfeo/core';
import { useStyle } from '@morfeo/hooks';
import { useStyle } from '@morfeo/react';

function Button() {
const style = useStyle({ componentName: 'Button' });
Expand All @@ -174,6 +111,11 @@ The value of `style` will be in this example equals to:
}
```

## Features
## Motivations

WIP
When your application starts to grow, maintain UI consistency it's not easy.
Even in popular applications we often face **wrong typographies**, different **color pallettes** used across different pages or inconsistent **spacings** in each component.

These problems are even more frequent in large applications where different teams works on different features (maybe with different technologies and frameworks).

**morfeo** solves this problem by sharing across all the application a customizable `theme` that contains the "language" of the application design and a `parser` that generate styles based on this language, in this way the UIs an the components are always consistent.
10 changes: 3 additions & 7 deletions docs/docs/Introduction/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ title: Getting started with Morfeo
description: Introduction > Getting started
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

Morfeo it's a tool to build design systems based on a theme.

It helps you to _follow a design language_ and write consistent UIs, whatever it is the framework of your choice.
Expand Down Expand Up @@ -72,7 +69,7 @@ Once you have a centralized theme, you need to parse this theme to generate the
This is an example with React

```tsx
import { theme, parsers } from '@morfeo/core';
import { parsers } from '@morfeo/web';

function Button() {
const style = parsers.resolve({ componentName: 'Button' });
Expand All @@ -81,11 +78,10 @@ function Button() {
}
```

Or if you want, you can use the hooks inside the package `@morfeo/hooks`
In the case of `React`, we built a package that suites it better: [@morfeo/react](https://morfeo.dev/docs/Packages/react)

```tsx
import { theme } from '@morfeo/core';
import { useStyle } from '@morfeo/hooks';
import { useStyle } from '@morfeo/react';

function Button() {
const style = useStyle({ componentName: 'Button' });
Expand Down
150 changes: 146 additions & 4 deletions docs/docs/Packages/hooks.mdx
Original file line number Diff line number Diff line change
@@ -1,10 +1,152 @@
---
sidebar_position: 2
sidebar_position: 4
id: hooks
title: hooks 🚧
title: hooks
description: morfeo's hooks package
---

:::caution
🚧 This section is still under construction
**@morfeo/hooks** expose a set of hooks to easily use morfeo inside a `react` context.

## Installation

```bash
# npm
npm i @morfeo/hooks

# yarn
yarn add @morfeo/hooks
```

- [useTheme](#usetheme)
- [useThemeSlice](#usethemeslice)
- [useThemeValue](#usethemevalue)
- [useStyles](#usestyles)
- [useStyle](#usestyle)

Advanced

- [useProps](#useprops)
- [useSubscribe](#usesubscribe)

## useTheme

Use this hook to get the current theme and use it inside a components:

```jsx
const MyComponent: React.FC = () => {
const theme = useTheme();

return (
<div>
<p>My primary color is: {theme.colors.primary}</p>
<p>My xxl space is: {theme.spaces.xxl}</p>
</div>
);
};
```

:::note
If you already know the [core API](./core) useTheme is the equivalent of `theme.get()`, the main difference is that useTheme react
to theme changes and force a re-render of the component.
:::

Most of the time you don't need all theme, but just a slice or single value, in this cases [useThemeSlice](#useThemeSlice) and [useThemeValue](#useThemeValue) can will give you only the part of the theme you want:

### useThemeSlice

```jsx
const MyComponent: React.FC = () => {
const colors = useThemeSlice('colors');

return (
<div>
<p>My primary color is: {colors.primary}</p>
<p>My secondary color is: {colors.secondary}</p>
</div>
);
};
```

### useThemeValue

```jsx
const MyComponent: React.FC = () => {
const primaryColor = useThemeValue('colors', 'primary');

return (
<div>
<p>My primary color is: {primaryColor}</p>
</div>
);
};
```

## useStyles

Most of the times you don't need the theme, but you need to generate a style based on the theme; The hooks `useStyles` and `useStyle` are made for this reason:

```jsx
const MyComponent: React.FC = () => {
const { agreeStyle, disagreeStyle, textStyle } = useStyles({
agreeStyle: { componentName: 'Button', variant: 'success' },
disagreeStyle: { componentName: 'Button' },
textStyle: { fontSize: 'xxl', color: 'white' },
});

return (
<div>
<p style={textStyle}>Nothing is better than a fresh beer in summer 🍺</p>
<button style={agreeStyle}>Oh yes! 🍻</button>
<button style={disagreeStyle}>What about a Coke? 🥤</button>
</div>
);
};
```
## useStyle
Use it if you need to generate just one style:
```jsx
const AgreeButton: React.FC = ({ children }) => {
const buttonStyle = useStyles({
componentName: 'Button',
variant: 'success',
});

return <button style={buttonStyle}>{children}</button>;
};
```
:::note
Just like useTheme, **useStyles** and **useStyle** are the equivalent of the [core API's](./core) `parsers.resove(style)`
but they force a re-render when the theme changes.
:::
## useProps
Use it to get the default props of a components, a common use is to merge the defaut props with the current props:
```jsx
function MyButton(props) {
const defaultProps = useProps('Button', 'primary');

return <button {...defaultProps} {...props} />;
}
```
## useSubscribe
If you just need to react to theme changes, `useSubscribe` receive a callback that will be executed every time the theme changes:
```jsx
function ThemeChangesCounter() {
const [counter, setCounter] = useState(0);

useSubscribe(() => {
setCounter(prev => prev + 1);
}, []);

return <div>The theme is changed {counter} times</div>;
}
```
2 changes: 1 addition & 1 deletion docs/docs/Packages/native.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
sidebar_position: 4
sidebar_position: 5
id: native
title: native 🚧
description: morfeo's native package
Expand Down
16 changes: 12 additions & 4 deletions docs/docs/Packages/react.mdx
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
---
sidebar_position: 3
id: react
title: react 🚧
title: react
description: morfeo's react package
---

:::caution
🚧 This section is still under construction
:::
## Installation

```bash
# npm
npm i @morfeo/react

# yarn
yarn add @morfeo/react
```

**@morfeo/react** re-expose [@morfeo/hooks](./hooks.mdx) and [@morfeo/web](./web.mdx), we suggest you to read their documentations.
Loading

0 comments on commit 4ad3b5d

Please sign in to comment.