Gathering detailed insights and metrics for codn
Gathering detailed insights and metrics for codn
Gathering detailed insights and metrics for codn
Gathering detailed insights and metrics for codn
Sustainable and lightweight react components based on the greenCSS style guide. SSR ready.
npm install codn
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
7.0.15
Package Id
codn@7.0.15
Unpacked Size
98.86 kB
Size
19.35 kB
File Count
7
NPM Version
8.15.0
Node Version
16.17.1
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.
The project is based on the sustainable-react package.
npm i codn
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 'codn' 3// import the styles 4import 'codn/dist/style/green.css' 5// if you want to use the greencss classNames: 6import 'greencss/css/greencss.css' 7 8export default function AccordionComponent() { 9 return ( 10 <div className='sans m-auto bg-gray-10 w-60rem rounded-20px shadow-small-gray-9'> 11 <div className='w-50rem m-auto py-50px'> 12 // default Accordion 13 <Accordion 14 className='bg-white rounded-5px' 15 expand='first title' 16 collapse='collapsed content' 17 headerStyleExpanded='text-15px font-600 text-purple pb-10px' 18 iconColorExpanded='stroke-purple' 19 /> 20 // Boxed Accordion 21 <Accordion boxStyle={true} expand='second title' collapse='second collapsed content' /> 22 </div> 23 </div> 24 ) 25}
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 |
border | ' border = 'focus:outline-1px focus:outline-solid focus:text-blue-9 text-blue-9 border-1px border-solid border-gray-10'' | Default border style |
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 'codn' 3// import the styles 4import 'codn/dist/style/green.css' 5 6export default function Home() { 7 const [toggleModal, setToggleModal] = useState(false) 8 return ( 9 <div className='min-h-100vh bg-gray-9'> 10 {/* Modal Toggle Button */} 11 <button onClick={() => setToggleModal((prev) => !prev)} className='bg-red-9 px-20px py-10px rounded-10px hover:bg-red-7'> 12 Toggle Modal 13 </button> 14 15 {/* Modal */} 16 <Modal toggle={toggleModal} setToggle={setToggleModal}> 17 <Modal.Header className='sans font-900 text-30px fade-in-left animation-duration-500ms animation-forwards'> 18 <h3>👋 Hi, I'm your modal</h3> 19 </Modal.Header> 20 <Modal.Body className='sans font-400 text-15px text-gray fade-in animation-duration-800ms animation-forwards'> 21 <p> 22 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna 23 aliqua. Viverra accumsan in nisl nisi scelerisque eu ultrices vitae auctor. Quis vel eros donec ac. Mauris 24 pellentesque pulvinar pellentesque habitant morbi tristique senectus. 25 </p> 26 <p> 27 Nunc non blandit massa enim nec dui nunc. Sed elementum tempus egestas sed sed risus. Senectus et netus et malesuada 28 fames ac turpis egestas maecenas. Urna nec tincidunt praesent semper feugiat. Est ante in nibh mauris cursus mattis 29 molestie. Vel elit scelerisque mauris pellentesque pulvinar pellentesque habitant. 30 </p> 31 </Modal.Body> 32 <Modal.Footer className='sans font-400 text-10px'> 33 <h3>copyright</h3> 34 </Modal.Footer> 35 </Modal> 36 </div> 37 ) 38}
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 'codn' 3// import the styles 4import 'codn/dist/style/green.css' 5 6export default function Home() { 7 const [toggleModal, setToggleModal] = useState(false) 8 return ( 9 <div className='min-h-100vh bg-gray-9'> 10 {/* Modal Toggle Button */} 11 <button onClick={() => setToggleModal((prev) => !prev)} className='bg-red-9 px-20px py-10px rounded-10px hover:bg-red-7'> 12 Toggle Modal 13 </button> 14 15 {/* Modal */} 16 <Modal toggle={toggleModal} setToggle={setToggleModal}> 17 <h3>👋 Hi, I'm your independent modal</h3> 18 <p> 19 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna 20 aliqua. Viverra accumsan in nisl nisi scelerisque eu ultrices vitae auctor. Quis vel eros donec ac. Mauris pellentesque 21 pulvinar pellentesque habitant morbi tristique senectus. 22 </p> 23 </Modal> 24 </div> 25 ) 26}
You can also use the codn 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 'codn' 3// import the styles 4import 'codn/dist/style/green.css' 5 6function App() { 7 const [toggleModal, setToggleModal] = useState(false) 8 return ( 9 <div className='App'> 10 {/* Modal Toggle Button */} 11 <button onClick={() => setToggleModal((prev) => !prev)} className='bg-red-9 px-20px py-10px rounded-10px hover:bg-red-7'> 12 Toggle Modal 13 </button> 14 15 {/* Modal */} 16 <Modal toggle={toggleModal} setToggle={setToggleModal}> 17 <Modal.Header className='sans font-900 text-30px fade-in-left animation-duration-500ms animation-forwards'> 18 <h3>👋 Hi, I'm your modal</h3> 19 </Modal.Header> 20 <Modal.Body className='sans font-400 text-15px text-gray fade-in animation-duration-800ms animation-forwards'> 21 <p> 22 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna 23 aliqua. Viverra accumsan in nisl nisi scelerisque eu ultrices vitae auctor. Quis vel eros donec ac. Mauris 24 pellentesque pulvinar pellentesque habitant morbi tristique senectus. 25 </p> 26 </Modal.Body> 27 <Modal.Footer className='sans font-400 text-10px'> 28 <h3>copyright</h3> 29 </Modal.Footer> 30 </Modal> 31 </div> 32 ) 33} 34 35export 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 |
modalPadding | true | Apply a 20px padding around the modal |
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 'codn' 3// import the styles 4import 'codn/dist/style/green.css' 5import 'codn/dist/style/input.css' 6// if you want to use the greencss classNames: 7import 'greencss/css/greencss.css' 8 9export default function AccordionComponent() { 10 const [password, setPassword] = useState('') 11 const [message, setMessage] = useState('') 12 return ( 13 <div className='sans m-auto bg-gray-10 w-60rem rounded-20px shadow-small-gray-9'> 14 // Specify your desired width 15 <div className='w-50rem m-auto py-50px'> 16 <Input 17 required={true} 18 id='password-field' 19 minlength={8} 20 maxLength={64} 21 value={password} 22 setValue={setPassword} 23 type='password' 24 htmlFor='password' 25 label='Your Password' 26 /> 27 <TextArea 28 maxLength={500} 29 id='message' 30 label='Message' 31 type='text' 32 value={message} 33 setValue={setMessage} 34 htmlFor='message' 35 /> 36 </div> 37 </div> 38 ) 39}
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 |
custom | "" | Add custom input related properties |
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 |
name | '' | Input field name |
1import React from 'react' 2import { CookieBanner } from 'codn' 3// import the styles 4import 'codn/dist/style/green.css' 5// if you want to use the greencss classNames: 6import 'greencss/css/greencss.css' 7 8export default function CookieComponent() { 9 return ( 10 <> 11 <CookieBanner position='top-right' shadow={false} header='greenCSS uses Cookies' buttonText='I want!'> 12 <p className='text-15px text-gray'> 13 Click “Accept” to enable greenCSS to use cookies in order to personalize this site for you. In this process you agree to 14 the storing of cookies and/or data in your local storage. You agree, that we use analytics to enhance site navigation 15 and analyze site usage. It helps us to improve the UI/UX experience for you. 16 </p> 17 </CookieBanner> 18 </> 19 ) 20}
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 |
className | "" | Set additional custom classNames |
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.
1import React, { useState } from 'react' 2import { handleShowToast, Toast } from 'codn' 3// import the styles 4import 'codn/dist/style/green.css' 5// if you want to use the greencss classNames: 6import 'greencss/css/greencss.css' 7 8export default function ToastComponent() { 9 const [toastList, setToastList] = useState([]) 10 return ( 11 <> 12 <button onClick={() => handleShowToast('info', 'Success', 'You did it! codn toast works successfully!', setToastList)}> 13 Show warning 14 </button> 15 <Toast 16 toastList={toastList} 17 setToastList={setToastList} 18 duration={5000} 19 position='top-right' 20 progressColor='from-blue to-magenta gradient-to-left' 21 /> 22 </> 23 ) 24}
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 |
---|---|---|
handleShowToast() | N/A | Function to set the toast type, title, description and the setToastList hook. |
toastList | toastList | useState hook call |
setToastList | setToastList | useState hook call |
duration | 5000 | Time to display the toast - in ms |
progressColor | '' | Default color for info ('bg-blue'), warning 'bg-orange', success ('bg-greencss') or error ('bg-red'). Set your own background-color class if you want to use your color |
position | 'top-right' | Possible positions: 'top-left', 'top-right','bottom-left','bottom-right' |
shadow | 'shadow-small-gray-5' | Display a shadow class (gray-5) |
⚠️ The handleShowToast()
must be configured for the toast component to work! This function takes 4 parameters:
1 const [toastList, setToastList] = useState([]) 2 ... 3<button onClick={() => handleShowToast('info', 'Information Header', 'You did it! The info text appears!', setToastList)}> 4 Show information toast 5</button> 6... 7<Toast 8... 9/>
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.
1import React, { useState } from 'react' 2import { Captcha } from 'codn' 3// import the styles 4import 'codn/dist/style/green.css' 5 6export default function CaptchaComponent() { 7 const [captcha, setCaptcha] = useState() 8 // check your console! 9 console.log(captcha) 10 return ( 11 <> 12 <Captcha setWord={setCaptcha} /> 13 </> 14 ) 15}
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 |
---|---|---|
setWord | null | useState hook call to verify the user input with the captcha |
numberOfCharacters | 5 | Default number of captcha characters |
backgroundColor | '#101010' | Default hex color of the canva's background color |
fontColor | '#f0eef5' | Default hex color of the canva's text color |
charset | 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!=?+*%&' | Default charset regex |
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.