GithubHelp home page GithubHelp logo

casavo / habitat Goto Github PK

View Code? Open in Web Editor NEW
3.0 4.0 0.0 3 MB

Casavo Design System Library

Home Page: https://casavo.github.io/habitat/

License: Apache License 2.0

JavaScript 1.61% TypeScript 83.80% MDX 13.77% HTML 0.82%
components design-system library react ui ux hacktoberfest

habitat's Introduction

Habitat - Casavo Design System Library

Welcome to the Casavo design system repository! This is where you can find all the components, guidelines and resources to create amazing user experiences for Casavo. Whether you are a developer, a designer or a product manager, you will find everything you need to get started. Explore the repository and have fun!

docs/images/meme.png

Design first

This project is a design driven project, which means we care a lot about the user experience and the aesthetics of our product. We want to create something that is beautiful, functional and easy to use.

Everything in this codebase is a reflection of what has been defined on the related Figma board.

Built on top of

  • React + Typescript - the library for web and native user interfaces
  • Vanilla Extract / Emotion - zero-runtime stylesheets in typeScript
  • Storybook - frontend workshop for building UI components and pages in isolation
  • Vite.js - next Generation Frontend Tooling

What's included?

You can check the public Storybook to test and experiment with the currently available components.

To sneak peek the incoming new features or components and participate in the discussions you can visit the issue section of this repo, or you can checkout the project's board to have a quick overview of the development status.

Using Habitat in your project

HEADS UP! currently you need

to add the Casavo private NPM registry token,

but we are planning to release this package as a public NPM one in the near future.

install the package in your project (you can use whatever package manager you prefer)

npm i @casavo/habitat

import the style.css and HabitatTheme global class and apply it to top level node of you application.

HEADS UP! the @casavo/habitat/style.css file will also apply a global CSS reset/normalise, it is suggested to remove existing reset solutions.

// src/pages/index.tsx - assuming it is a Next.js application
import Head from "next/head";
import {FC} from "react";

import "@casavo/habitat/style.css";
import {HabitatTheme} from "@casavo/habitat";

export default function Home(): FC => {
  return (
    <>
      <Head>
        <title>Next app + Habitat DS</title>
      </Head>
      <main id="app" className={HabitatTheme}>
        {children}
      </main>
    </>
  );
};

then import and use the components that you need in yout code

// MyComponent.tsx
import {Button} from "@casavo/habitat";

export const MyComponent = (): FC => {
  const variant: string = "secondary";

  const doSomething = (): void => window.alert("button clicked!");

  return (
    <div>
      <Button variant={variant} onClick={doSomething}/>
    </div>
  );
};

you can also import a specific component directly

import {Badge} from "@casavo/habitat/badge"
import {Button} from "@casavo/habitat/button"
import {Checkbox} from "@casavo/habitat/checkbox"
import {Switch} from "@casavo/habitat/switch"
import { H1, H2, H3, H4, H5, H6, Body, Inline } from "@casavo/habitat/typography"
Habitat Components RSC
Badge
Button
Checkbox
Typography

Local development

Clone the repo and cd into it

git clone [email protected]:casavo/habitat.git
cd habitat

install the NPM dependencies

npm ci

start the Storybook development server

npm run dev

the Storybook instance will automatically open in your browser at http://localhost:6006/.

Please refert to the docs for in depth info on how to work locally.

How to participate?

Before opening issues or pull requests plaese read our code of conduct, then refer to the guidelines described in the "Contributing" section.

For information, requests, bug and inconsistencies alerts join the #habitat-design-system Slack channel.

Updating the Design Tokens (WiP)

This library heavily relies on a set of Design Tokens defined in the Figma board. When the tokens changes on the source board, the designers exports a new .json file that the developers can integrate in the repo and use by following this steps:

  1. copy the .json generated by Figma in the root folder of the project

    • if the file has the same name of the existing one just overwrite it
    • if the file name change delete the existing one and update the source value in the dictionary.config.json file
  2. from the terminal execute $ npm run update:tokens

  3. this will generate a new plain .json token file in the src/utils folder

  4. commit the changes, push the code and create a new PR as described in the "Contributing" section

(Very short) FAQ

How to use i18n strings that includes HTML entities?

With next-translate we already have a dedicated component that handles the HTML interpolation, you can use it as children to any of our components as following:

import { Body, Inline } from "@casavo/habitat"
import Trans from "next-translate/Trans"

<Body>
  <Trans
    components={{
      strong: <Inline strong />,
    }}
    i18nKey={"context:my-text"}
  />
</Body>

so as you can see we are correctly rendering the HTML markup inside the component and also mapping any <strong> tag defined in the i18n string with an <Inline> Habitat component.

In the case where you are not receiving the i18nKey string but just a string with HTML content within, you can use the html="" prop that we added in every typography components:

import { Body } from "@casavo/habitat"

const HTMLstring = `Some <strong>text</strong> with HTML entities. <br /> Enjoy!`;

<Body html={HTMLstring} />

that prop is a wrapper for React's dangerouslySetInnerHTML, and should be used as a last resort

Is it possible to use Habitat in a Casavo project that is already using other styling solutions?

Yes, so far we did it in project that were using Emotion and Vanilla Extract with another theme and we never got any issue. So this opens the way to a progressive adoption in your existing project.

Can I use this library in a non React or Node.js environment?

There is a related discussion in the issue section of this repository.

Which "parts" can be used as non-React stuff?

  • the Design Tokens .json file
  • the CSS reset applied in the style.css file
  • the vars object exported from /src/utils/theme.ts

License

Code is distributed under the Apache 2.0, Casavo logo and brand are registered trademarks.

habitat's People

Contributors

elleuca avatar giovannivisentinicasavo avatar marcel-casavo avatar moebiusmania avatar pietrograndi avatar serse2 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

habitat's Issues

typography

most of the typography components are already defined and built, but they need some styling fixes

  • <Small /> will not be developed and it will instead become a 3rd parameter of <Body />
  • the list has already been defined in #7

improve Storybook pages

At the moment the Storybook pages are just displaying the compoent, but we could use all that empty space to provide useful informations for consumers of the library.

In general

  • use Habitat styles and component to compose the page
  • update the first page deleting the template content
  • add a media queries doc page? (similar to colors)

What we could include in each page?

  • component tag as title of the page
  • import line of the component/utility
  • brief desciption?
  • link to related figma page?

module declarations issue

image

Repro steps

  1. install Habitat in a project npm i @casavo/habitat
  2. import a module like import { HabitatTheme } from "@casavo/habitat"
  3. VS Code should mark the import line as the screenshot above

Quick solution

add a // @ts-ignore comment above the import line

Switch Component: not aligned indicator

As you can see from the image
the indicator of the component is not aligned correctly,
image
There has been some regression, but I haven't verified it yet.
It would be nice to check the origin of the regression and whether other components have been affected.

<TextLink />

Figma design

https://www.figma.com/file/0vYcLbHGHFIJ44hFI45WQJ/%F0%9F%9A%80-Habitat?node-id=8144%3A5565&mode=dev

How to use

<TextLink href="#">I'm an external link</TextLink>

Props

It inherits all the props of an <a /> tag plus

Name Type Default is optional? other values
variant string "light" yes "dark, "success", "warning", "error"

Notes

the styles within the component should be defined as Vanilla Extract's Recipes and the resulting utility will be exported and used independently.

split imports

As of v1.0-beta everything within the Habitat library is exported from a single entry point @casavo/habitat/index.js this is decent DX since it allows to have multiple imports on one line of code but has some downsides most notably it will break the usage of the library on Next.js v13+ with /app router architecture, which will be a critical issue in a near future (this happens because we are basically importing everything in the library, including components using client-side only features like useState() that can't be used in server components, the new default in the latest Next.js architecture).

The alternative will be to split the imports one by one like:

import { H1, Body } from "@casavo/habitat/Typography"
import Button from "@casavo/habitat/Button"
import Checkbox from "@casavo/habitat/Checkbox"

which is better in terms of optimizations and should solve the above mentioned issue but may require various line of imports if many Habitat components/utils are used in the same file.

there are other options available that I'm not considering?
suggestions and opinions are welcome

Typography components can't render some i18n results

when using a typography component with something like an i18n function returning a string with tags as children, like this

<H1>{t('string-with-a-link-inside')}</H1>

the resulting HTML within the tag will be rendered as a string rather than as tag.

things to be aware of:

  • the children prop work as expected when passing text, React components, static HTML, i18n function with no HTML within
  • children prop is typed as React.ReactNode (it should be a common practice but I may be wrong)
  • only this specific use case is requiring the html={} prop

Solution

Exposing the dangerouslySetInnerHTML React directive in a component prop to avoid using extra markup


EDIT 02/04/2023

as of #36 I've added a html={} prop to every typography component that as the issue states just offer a controlled way to access dangerouslySetInnerHTML directive.

If anyone find a better way to handle this problem feel free to re-open this issue and send a PR, I wouldn't remove the html={} as it may helps handle some edge cases (as last resorst) in the future.

publish package

update the CI pipeline to publish the library under the company namespace at @casavo/habitat

Acceptance criteria

  • pushing on main branch doesnt trigger an update of the package
  • creating a new GH release will trigger an update of the package
  • the package can be installed on any project with $ npm install @casavo/habitat
  • the documentation is updated

add CDN files and integration

currently the static CDN files used in every projects and hosted at https://cdn-base-ui.casavo.com/ are stored within the base-ui repo https://github.com/casavo/base-ui/tree/master/packages/static-assets , since in the long term we won't maintain all of the libraries repositories, we can start moving that part within the Habitat repo to have a single place for shared components, styles and assets.

  • static assets files are moved from base-ui repo to habitat repo
    • use a /cdn folder
  • update the CI to push the /cdn folder to https://cdn-base-ui.casavo.com/ when the main branch is updated
  • update the documentation about static CDN assets

Enable chromatic deployment by label

Chromatic deployment is automated by default when a PR leaves a draft.
The idea is to add a specific label to enable chromatic distribution only for builds where it is needed.

<Button />

Figma design

https://www.figma.com/file/0vYcLbHGHFIJ44hFI45WQJ/%F0%9F%9A%80-Habitat?node-id=8133%3A5464

Props

Name Type Default is optional? other values
variant string "primary" yes "secondar", "tertiary"
type string "button" yes "submit", "reset"
rounded boolen false yes
size string "medium" yes "large", "small"
loader boolen false yes
iconOnly boolen false yes
iconLayout string "sx" yes "dx"
icon component yes
theme string "light" yes "dark"

Notes

the button text must be as children not as prop

add "Brand" section

to converge also the Marketing team brand efforts and documentation we are including the brand guidelines docs currently published at https://casavo.hypedev.23x.me/ and add them in the Habitat Storybook.

  • create new Brand section in Storybook
  • re-create at least "Strategy", "Concept" & "Tone of voice"
  • add the downloads files?

this is a complementing activity of #41

CSS reset

we need to introduce a CSS reset, but we are facing 2 options:

  • adding it only to the Storybook and then each project that use Habitat should handle itself
  • making it an exportable utility within Habitat

typography & font weight

It seems some typography components, more specifically H3, H4, H5, H6 have an incorrect font weight.

The weight documented on figma is 500, while in the codebase the weight is 400.
During the previous working group discussion it was decided that the correct font weight is the one documented on figma so we should open a PR about this.

non React/JS environments support?

as of v1.0-beta Habitat is a React only library.

Even though React is a Javascript framework, nothing built in React can be reused in different frameworks or environment as it is, to achieve this goal additional work is always required.

Why Habitat is React only?

The context here is that being React+Next the only JS framework that we are using in Casavo, there is no need to consider other JS based solutions. We have some non React/JS projects but to support them from the beginning we would had to heavily compromise the developer experience for the 90% of the consumer of the library, so we took the "obvious" solution to start building the library with the bigger userbase in mind.

What other environments could use Habitat?

Given that as stated above, we don't have JS projects built with anything different from React, only the backend-first language remains (Elixir, Python, Scala, Kotlin) so the only feasible choice woul be to support Web Components since they can be injected from the server (but rendered on the client anyway).

Do we HAVE TO consider non React/JS environments?

At the time that I'm writing this we had NO requests to implement this kind of compatibility. But since we are going to unveil the library in a few days, I would not be surprised if a similar question would pop out in the coming weeks so it can be a good idea to at least have a discussion about it to get some opinions.
Technically the objective of a Design System (and the library that materialize it) is to consolidate and unify the design and UX across any products of a company, so in the long term it makes sense to address this issue.

What options are available to eventually achieve this result?

  • StencilJS
    • 🟢 code is JSX (but not React) and the components can be built to different outputs (WebComponents, Vue, etc)
    • 🔴 requires complete rewrite of the current codebase, not sure about reusing Vanilla Extract
  • writing Web Components from scratch alongside the React ones
    • 🟢 we can reuse most of the existing code and have native Web Components
    • 🔴 markup and logic must be ported, an additional build + release pipeline must be added to the project
  • using a wrapper library like react-to-web-components
    • 🟢 all of the current code is reused, we just need to add the props and events bindings
    • 🔴 not sure how the CSS is treated, not sure if an istance of React is embedded in every component or not, an additional build + release pipeline must be added to the project
  • ditching components entirely, just exporting the Vanilla Extract classes as regular CSS classes (Bootstrap style)
    • 🟢 very low effort, not adding JS in projects that aren't using it
    • 🔴 components logic should be re-implemented every time, an additional build + release pipeline must be added to the project

EDIT: I'm not mentioning React Native envs so far since we already had a first exploration on that topic and we haven't found a feasible solution to share logic across React Web and Native. Only some smaller utilities can be shared.

any other ideas, solutions, opinions and suggestions on this topic are welcome in the discussion below.

<CheckGroup />

Figma design

https://www.figma.com/file/0vYcLbHGHFIJ44hFI45WQJ/%F0%9F%9A%80-Habitat?node-id=11349%3A15999&mode=dev

How to use

<CheckGroup>
  <Checkbox checked={true}>Label for the item</Checkbox>
  <Checkbox checked={true}>Label for the item</Checkbox>
  <ul>
    <li><Checkbox checked={true}>Label for the item</Checkbox>
    <li><Checkbox checked={true}>Label for the item</Checkbox>
  </ul>
</CheckGroup>

expected HTML output

<ul>
  <li><input type="checkbox" checked> <label>Label for the item</label></li>
  <li><input type="checkbox" checked> <label>Label for the item</label></li>
  <li>
    <ul>
       <li><input type="checkbox" checked> <label>Label for the item</label></li>
       <li><input type="checkbox" checked> <label>Label for the item</label></li>
    </ul>
  </li>
</ul>

Notes

let's investigate the possibility to use React Children utility.

typography & colors

currently the Storybook page for Typography components expose a color control, and that prop is accepted by the components but its not used in the code.

This is a leftover of an unfinished discussion regarding how we want to handle colors for typography (accept any color value thus breaking the DS guidelines or expose a subset via props?).

### Quick fix
remove the color property or set it to accept any color value and set it as style={} on the element

We have defined with the designers how to handle the colors in typography

Requirement

All of the typography components should expose a prop that allow a user of the components to choose one of the colors available in the tokens file.

No restrictions will be applied for the moments except that an user can't apply whatever color they want outside of the ones being part of the DS

⚠️ warning

some colors are still missing in the design token file

opening the project

we are going to make this repo a public Open Source project!

a couple of things needs to be done before going public:

  • clear documentation
  • update license from MIT to Apache 2.0
  • update contrib guidelines
  • create project
  • create issues
  • distribute work across devs

CSS only version

following #27 we are going to introduce a first iteration of a "CSS only" version of Habitat in v1.0, to provide basic library usage and UI/UX consistency in regular HTML environments, especially landing pages buit with 3rd party tools.

  • habitat tokens usable as CSS classes
  • typography elements usable as CSS classes
  • habitat components usable as CSS classes
  • provide examples on Storybook
  • update documentation

some parts will be dependants on #50

<Navbar />

🚧 let's keep this one on hold 🚧

Figma design

https://www.figma.com/file/0vYcLbHGHFIJ44hFI45WQJ/%F0%9F%9A%80-Habitat?node-id=9295%3A8033&mode=dev

How to use

<Navbar theme="B2C">
  <a href="#">Link 1</a>
  <a href="#">Link 2</a>
</Navbar>

expected HTML output

<nav>
  <ul>
    <li><a href="#">Link 1</a></li>
    <li><a href="#">Link 1</a></li>
  </ul>
</nav>

Props

Name Type Default is optional? other values
variant string "B2B" yes "B2C", "mortgage"

Notes

  • the logos will imported in the component
  • could we want to mix background color and logos?
  • is the white background version an actual variant to style?
  • what is the last label after the "|" ?
  • do we expect nested list items?
  • let's check on this https://react.dev/reference/react/Children

public package

update the settings and the documentation to make this package installable by anyone.

we need to investigate to check if we can create a public package directly in Github or if we need to create a dev NPM accont and publish it there.

storybook controls

for some reason before being able to interact with a control in Storybook a "set [type]" button appears on top of the control itself, as shown in the image below

image

is this some misconfiguration or bug introduced by me?
please help me understand the cause and fix

theming

Habitat DS must be a themable library.

Every project that use it should be able to pass a set of custom Design Tokens (provided by the Casavo Design team) as json file and see the new changes without the need of touching the source components code or overriding their appearance through parent style.

We are going to achieve this by mixing the Theming utilities of Vanilla Extract and the Style Dictionary implementation that we have already provided within the repo (nice to have: expose the CLI command to generate the plain .json token file to the parent project using this library)

Acceptance criteria

  • theming implemented within the library
  • documentation updated to explain how to use the theme values within the library
  • documentation updated to explain how to use custom themes in parent projects

post-merge branch delete

at the moment when you aprrove a merge a PR the branch isnt deleted automagically as it happens in other projects, it would be nice to bring this feature here

<Radio />

Figma design

https://www.figma.com/file/0vYcLbHGHFIJ44hFI45WQJ/%F0%9F%9A%80-Habitat?type=design&node-id=10289-12015&mode=design&t=E2nIpsXexs5ZkKi7-0

How to use

<Radio checked={true}>Label for the item</Radio>

Props

it inherits all of the native <input type="checkbox"> attributes es exposed by https://react-spectrum.adobe.com/react-aria/RadioGroup.html plus:

Name Type Default is optional? other values
variant string "B2C" yes "B2B", "neutral"

Notes

  • the checkbox label is define through the children prop of the component

<Checkbox />

Figma design

https://www.figma.com/file/0vYcLbHGHFIJ44hFI45WQJ/%F0%9F%9A%80-Habitat?node-id=11349%3A15999&mode=dev

How to use

<Checkbox checked={true}>Label for the item</Checkbox>

Props

it inherits all of the native <input type="checkbox"> attributes plus:

Name Type Default is optional? other values
variant string "B2C" yes "B2B", "neutral"
checked boolean true yes
error boolean true yes
message string yes "Error message"

Notes

  • the checkbox label is define through the children prop of the component

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.