Gathering detailed insights and metrics for sustainable-react
Gathering detailed insights and metrics for sustainable-react
Gathering detailed insights and metrics for sustainable-react
Gathering detailed insights and metrics for sustainable-react
@sustainableui/sui-headless-react
SUI Headless for React
ecocart-react-components
EcoCart's reusable and sustainable React component library.
next-modal
A sustainable and lightweight react modal component project based on greenCSS. SSR ready.
codn
Sustainable and lightweight react components based on the greenCSS style guide. SSR ready.
Sustainable and lightweight react components based on the greenCSS style guide. SSR ready.
npm install sustainable-react
Typescript
Module System
Node Version
NPM Version
JavaScript (99.1%)
CSS (0.44%)
Shell (0.39%)
HTML (0.07%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
2 Stars
118 Commits
1 Watchers
1 Branches
2 Contributors
Updated on Apr 25, 2023
Latest Version
5.1.4
Package Id
sustainable-react@5.1.4
Unpacked Size
59.02 kB
Size
13.07 kB
File Count
5
NPM Version
8.15.0
Node Version
16.16.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
32
This is a sustainable React component project based on greenCSS. The components work with plain React, as well as with SSR - such as Next.js. Animations and the basic design were realised with greenCSS. greenCSS is an animated, responsive, lightweight and sustainable CSS library. It is recommended that you also use greenCSS in your project. If you don't want to, just style your modal with your own classes.
npm i sustainable-react
The example below uses greenCSS for styling. Download greenCSS or learn more on the greenCSS website. Alternatively to greenCSS you can insert your own classNames. The Accordion can be operated with the keyboard (Tab / Enter) as well as clicked.
1import React from 'react' 2import { Accordion } from 'sustainable-react' 3// if you want to use the greencss classNames: 4import 'greencss/css/greencss.css' 5 6export default function AccordionComponent() { 7 return ( 8 <div className='sans m-auto bg-gray-10 w-60rem rounded-20px shadow-small-gray-9'> 9 <div className='w-50rem m-auto py-50px'> 10 // default Accordion 11 <Accordion 12 className='bg-white rounded-5px' 13 expand='first title' 14 collapse='collapsed content' 15 headerStyleExpanded='text-15px font-600 text-purple pb-10px' 16 iconColorExpanded='stroke-purple' 17 /> 18 // Boxed Accordion 19 <Accordion boxStyle={true} expand='second title' collapse='second collapsed content' /> 20 </div> 21 </div> 22 ) 23}
You can adjust the default values listed below at any time with your values or classNames. Be aware that you may have to readjust the design. Therefore, a change is only recommended if you really know what you are doing.
Name | Default Value | Description |
---|---|---|
expand | 'Your title' | Your title |
collapse | 'Your collapsed content' | Your collapsed content |
className | 'bg-white' | Use your own className to style the Accordion |
boxStyle | false | Secondary Accordion design |
shadow | true | Set a shadow around the secondary icon |
headerStyle | 'text-15px font-600 text-black' | Default "expand" title design |
collapseStyle | 'text-15px text-black' | Default text style for collapsed content |
headerStyleExpanded | 'text-15px font-600 text-blue pb-10px' | Default "expand" title design if expanded |
iconColorCollapse | 'stroke-black' | Default icon className if collapsed |
iconColorExpanded | 'stroke-blue' | Default icon color if expanded |
circleCollapse | 'shadow-small-gray-10 bg-white' | Default circle color around the boxStyle icon if collapsed |
circleExpand | 'rotate-90deg bg-blue' | Default circle color around the boxStyle icon if expanded |
fade-in animation-duration-500ms animation-forwards
. If you want to animate the Modal.Header
or Modal.Body
, just add your greenCSS or your custom animation as a class to the className
. Here can find all greenCSS animations. p.e. <Modal.Body className='clip-circle-in-left animation-duration-800ms animation-forwards'>
closeIcon
with your own (svg-) component. <Modal toggle={toggleModal} setToggle={setToggleModal} closeIcon={<div>X</div>}>
The recommended size for an svg is 20x20px.prefers-reduced-motion: reduce
In the pages directory, add _document.js
. It is important to add <div id='modal-portal' />
below the <Main />
component. Otherwise your SSR Modal will not work. Learn more about the custom document.
1// pages/_document.js 2import Document, { Html, Head, Main, NextScript } from 'next/document' 3 4class MyDocument extends Document { 5 static async getInitialProps(ctx) { 6 const initialProps = await Document.getInitialProps(ctx) 7 return { ...initialProps } 8 } 9 10 render() { 11 return ( 12 <Html> 13 <Head /> 14 <body> 15 <Main /> 16 <div id='modal-portal' /> 17 <NextScript /> 18 </body> 19 </Html> 20 ) 21 } 22} 23export default MyDocument
The following jsx file below is based on greenCSS. If you don't want to use it, you can add your own classNames
.
1import React, { useState } from 'react' 2import { Modal } from 'sustainable-react' 3 4export default function Home() { 5 const [toggleModal, setToggleModal] = useState(false) 6 return ( 7 <div className='min-h-100vh bg-gray-9'> 8 {/* Modal Toggle Button */} 9 <button onClick={() => setToggleModal((prev) => !prev)} className='bg-red-9 px-20px py-10px rounded-10px hover:bg-red-7'> 10 Toggle Modal 11 </button> 12 13 {/* Modal */} 14 <Modal toggle={toggleModal} setToggle={setToggleModal}> 15 <Modal.Header className='sans font-900 text-30px fade-in-left animation-duration-500ms animation-forwards'> 16 <h3>👋 Hi, I'm your modal</h3> 17 </Modal.Header> 18 <Modal.Body className='sans font-400 text-15px text-gray fade-in animation-duration-800ms animation-forwards'> 19 <p> 20 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna 21 aliqua. Viverra accumsan in nisl nisi scelerisque eu ultrices vitae auctor. Quis vel eros donec ac. Mauris 22 pellentesque pulvinar pellentesque habitant morbi tristique senectus. 23 </p> 24 <p> 25 Nunc non blandit massa enim nec dui nunc. Sed elementum tempus egestas sed sed risus. Senectus et netus et malesuada 26 fames ac turpis egestas maecenas. Urna nec tincidunt praesent semper feugiat. Est ante in nibh mauris cursus mattis 27 molestie. Vel elit scelerisque mauris pellentesque pulvinar pellentesque habitant. 28 </p> 29 </Modal.Body> 30 <Modal.Footer className='sans font-400 text-10px'> 31 <h3>copyright</h3> 32 </Modal.Footer> 33 </Modal> 34 </div> 35 ) 36}
Do you want to use your style within the modal? No problem - you can add any JSX inside.
1import React, { useState } from 'react' 2import { Modal } from 'sustainable-react' 3 4export default function Home() { 5 const [toggleModal, setToggleModal] = useState(false) 6 return ( 7 <div className='min-h-100vh bg-gray-9'> 8 {/* Modal Toggle Button */} 9 <button onClick={() => setToggleModal((prev) => !prev)} className='bg-red-9 px-20px py-10px rounded-10px hover:bg-red-7'> 10 Toggle Modal 11 </button> 12 13 {/* Modal */} 14 <Modal toggle={toggleModal} setToggle={setToggleModal}> 15 <h3>👋 Hi, I'm your independent modal</h3> 16 <p> 17 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna 18 aliqua. Viverra accumsan in nisl nisi scelerisque eu ultrices vitae auctor. Quis vel eros donec ac. Mauris pellentesque 19 pulvinar pellentesque habitant morbi tristique senectus. 20 </p> 21 </Modal> 22 </div> 23 ) 24}
You can also use the sustainable-react modal in your create-react-app. Head to your public/index.html
file and add <div id="modal-portal" />
below the <div id="root"></div>
.
1<!DOCTYPE html> 2<html lang="en"> 3 <head> 4 <meta charset="utf-8" /> 5 <link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> 6 <meta name="viewport" content="width=device-width, initial-scale=1" /> 7 <meta name="theme-color" content="#000000" /> 8 <meta name="description" content="Web site created using create-react-app" /> 9 <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" /> 10 <link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> 11 <title>React App</title> 12 </head> 13 <body> 14 <noscript>You need to enable JavaScript to run this app.</noscript> 15 <div id="root"></div> 16 <div id="modal-portal" /> 17 </body> 18</html>
Within a page or a component, you can now add and use the Modal.
1import React, { useState } from 'react' 2import { Modal } from 'sustainable-react' 3 4function App() { 5 const [toggleModal, setToggleModal] = useState(false) 6 return ( 7 <div className='App'> 8 {/* Modal Toggle Button */} 9 <button onClick={() => setToggleModal((prev) => !prev)} className='bg-red-9 px-20px py-10px rounded-10px hover:bg-red-7'> 10 Toggle Modal 11 </button> 12 13 {/* Modal */} 14 <Modal toggle={toggleModal} setToggle={setToggleModal}> 15 <Modal.Header className='sans font-900 text-30px fade-in-left animation-duration-500ms animation-forwards'> 16 <h3>👋 Hi, I'm your modal</h3> 17 </Modal.Header> 18 <Modal.Body className='sans font-400 text-15px text-gray fade-in animation-duration-800ms animation-forwards'> 19 <p> 20 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna 21 aliqua. Viverra accumsan in nisl nisi scelerisque eu ultrices vitae auctor. Quis vel eros donec ac. Mauris 22 pellentesque pulvinar pellentesque habitant morbi tristique senectus. 23 </p> 24 </Modal.Body> 25 <Modal.Footer className='sans font-400 text-10px'> 26 <h3>copyright</h3> 27 </Modal.Footer> 28 </Modal> 29 </div> 30 ) 31} 32 33export default App
Name | Default Value | Description |
---|---|---|
toggle | - | useState toggle state |
setToggle | - | useState toggle setToggle |
useKeyInput | true | Use the default key inputs "CTRL + k" to open the modal and "ESC" to close the modal |
shadow | true | Set a black shadow modal content |
className | "" | Use your own className to style the modal content |
backgroundAnimation | 'fade-in animation-duration-500ms animation-forwards' | Add your custom animation className in order to overwrite the default fade in animation for the background |
modalContentAnimation | 'fade-in animation-duration-500ms animation-forwards' | Add your custom animation className in order to overwrite the default fade in animation for the modal content component |
closeIcon | <CloseIcon /> | Add your own close icon on the top right, may be an svg or your custom component |
<Modal> | <Modal>{children}</Modal> | This is the Modal component. Add your own child element(s) or use the <Modal.Header> and <Modal.Body> inside. |
<Modal.Header> | <Modal.Header>{children}</Modal.Header> | Add a header text |
<Modal.Body> | <Modal.Body>{children}</Modal.Body> | Add body elements |
<Modal.Footer> | <Modal.Footer>{children}</Modal.Footer> | Add footer elements |
The example below uses greenCSS for styling. Download greenCSS or learn more on the greenCSS website. Alternatively to greenCSS you can insert your own classNames. The Accordion can be operated with the keyboard (Tab / Enter) as well as clicked.
⚠️ The width of the input field is 100%. Specify a desired width in the parent element if needed. ⚠️ The input fields are not protected against XSS attacks.
1import React, { useState } from 'react' 2import { Input, TextArea } from 'sustainable-react' 3// if you want to use the greencss classNames: 4import 'greencss/css/greencss.css' 5 6export default function AccordionComponent() { 7 const [password, setPassword] = useState('') 8 const [message, setMessage] = useState('') 9 return ( 10 <div className='sans m-auto bg-gray-10 w-60rem rounded-20px shadow-small-gray-9'> 11 // Specify your desired width 12 <div className='w-50rem m-auto py-50px'> 13 <Input 14 required={true} 15 id='password-field' 16 minlength={8} 17 maxLength={64} 18 value={password} 19 setValue={setPassword} 20 type='password' 21 htmlFor='password' 22 label='Your Password' 23 /> 24 <TextArea 25 maxLength={500} 26 id='message' 27 label='Message' 28 type='text' 29 value={message} 30 setValue={setMessage} 31 htmlFor='message' 32 /> 33 </div> 34 </div> 35 ) 36}
You can adjust the default values listed below at any time with your values or classNames. Be aware that you may have to readjust the design. Therefore, a change is only recommended if you really know what you are doing.
Name | Default Value | Description |
---|---|---|
label | The input label | Title of your input or textarea |
required | false | Determine if your input is required or not |
autofocus | false | Determine if your input is auto selected |
shadow | true | Set a gray-9 (#eaeaea) shadow |
id | '' | ID of your input/textarea |
value | '' | useState value state |
setValue | '' | useState setValue state |
htmlFor | '' | htmlFor state |
minlength | '' | Minimum number of characters |
maxLength | '' | Maximum number of characters |
type | 'text' | Input field type |
1import React from 'react' 2import { CookieBanner } from 'sustainable-react' 3// if you want to use the greencss classNames: 4import 'greencss/css/greencss.css' 5 6export default function CookieComponent() { 7 return ( 8 <> 9 <CookieBanner position='top-right' shadow={false} header='greenCSS uses Cookies' buttonText='I want!'> 10 <p className='text-15px text-gray'> 11 Click “Accept” to enable greenCSS to use cookies in order to personalize this site for you. In this process you agree to 12 the storing of cookies and/or data in your local storage. You agree, that we use analytics to enhance site navigation 13 and analyze site usage. It helps us to improve the UI/UX experience for you. 14 </p> 15 </CookieBanner> 16 </> 17 ) 18}
Name | Default Value | Description |
---|---|---|
position | 'bottom-right' | The cookie position, possible locations: 'top-left', 'top-right', 'bottom-left', 'bottom-right' |
shadow | true | Set a shadow around the secondary icon |
header | '🍪 Our website uses cookies' | Set a custom cookie title |
buttonText | 'Accept' | Set a custom cookie button text |
showButton | true | Show the button which shows the footer button - if you disable it, localstorage functionality will no longer be available. |
buttonStyle | 'cursor-pointer flex py-10px px-25px min-w-50px font-bold transition-duration-200ms transition-all rounded-10px border-1px border-solid border-black my-auto text-center justify-center items-center m-auto text-15px text-black hover:bg-black hover:text-white' | Set a custom cookie button style |
{ children } | Our website use cookies. By continuing, we assume your permission to deploy cookies as detailed in our Privacy Policy. | Set a custom body content |
We use semantic versioning for commit messages.
For commit messages, use semantig writing:
Commit | Usage | Version |
---|---|---|
fix(your-change): a small change, p.e. fixed a component, readme or test | Fix Release | v.0.0.1 |
feat(your-change): a new feature, p.e. test suite for a component | Feature Release | v.0.1.0 |
perf(your-change): a breaking change or hotfix \n BREAKING CHANGE: p.e. added a new component | Breaking Release | v.1.0.0 |
A breaking change must be written in the footer. p.e.
`perf(your-change): a breaking change or hotfix
BREAKING CHANGE: First line of explanation Other lines of explanations`
Possible commit values are:
1[ 2 'build', 3 'chore', 4 'ci', 5 'docs', 6 'feat', 7 'fix', 8 'perf', 9 'refactor', 10 'revert', 11 'style', 12 'test' 13];
No vulnerabilities found.
No security vulnerabilities found.