
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Sustainable and lightweight react components based on the greenCSS style guide. SSR ready.
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.
import React from 'react'
import { Accordion } from 'codn'
// if you want to use the greencss classNames:
import 'greencss/css/greencss.css'
export default function AccordionComponent() {
return (
<div className='sans m-auto bg-gray-10 w-60rem rounded-20px shadow-small-gray-9'>
<div className='w-50rem m-auto py-50px'>
// default Accordion
<Accordion
className='bg-white rounded-5px'
expand='first title'
collapse='collapsed content'
headerStyleExpanded='text-15px font-600 text-purple pb-10px'
iconColorExpanded='stroke-purple'
/>
// Boxed Accordion
<Accordion boxStyle={true} expand='second title' collapse='second collapsed content' />
</div>
</div>
)
}
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.
// pages/_document.js
import Document, { Html, Head, Main, NextScript } from 'next/document'
class MyDocument extends Document {
static async getInitialProps(ctx) {
const initialProps = await Document.getInitialProps(ctx)
return { ...initialProps }
}
render() {
return (
<Html>
<Head />
<body>
<Main />
<div id='modal-portal' />
<NextScript />
</body>
</Html>
)
}
}
export 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
.
import React, { useState } from 'react'
import { Modal } from 'codn'
export default function Home() {
const [toggleModal, setToggleModal] = useState(false)
return (
<div className='min-h-100vh bg-gray-9'>
{/* Modal Toggle Button */}
<button onClick={() => setToggleModal((prev) => !prev)} className='bg-red-9 px-20px py-10px rounded-10px hover:bg-red-7'>
Toggle Modal
</button>
{/* Modal */}
<Modal toggle={toggleModal} setToggle={setToggleModal}>
<Modal.Header className='sans font-900 text-30px fade-in-left animation-duration-500ms animation-forwards'>
<h3>👋 Hi, I'm your modal</h3>
</Modal.Header>
<Modal.Body className='sans font-400 text-15px text-gray fade-in animation-duration-800ms animation-forwards'>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Viverra accumsan in nisl nisi scelerisque eu ultrices vitae auctor. Quis vel eros donec ac. Mauris
pellentesque pulvinar pellentesque habitant morbi tristique senectus.
</p>
<p>
Nunc non blandit massa enim nec dui nunc. Sed elementum tempus egestas sed sed risus. Senectus et netus et malesuada
fames ac turpis egestas maecenas. Urna nec tincidunt praesent semper feugiat. Est ante in nibh mauris cursus mattis
molestie. Vel elit scelerisque mauris pellentesque pulvinar pellentesque habitant.
</p>
</Modal.Body>
<Modal.Footer className='sans font-400 text-10px'>
<h3>copyright</h3>
</Modal.Footer>
</Modal>
</div>
)
}
Do you want to use your style within the modal? No problem - you can add any JSX inside.
import React, { useState } from 'react'
import { Modal } from 'codn'
export default function Home() {
const [toggleModal, setToggleModal] = useState(false)
return (
<div className='min-h-100vh bg-gray-9'>
{/* Modal Toggle Button */}
<button onClick={() => setToggleModal((prev) => !prev)} className='bg-red-9 px-20px py-10px rounded-10px hover:bg-red-7'>
Toggle Modal
</button>
{/* Modal */}
<Modal toggle={toggleModal} setToggle={setToggleModal}>
<h3>👋 Hi, I'm your independent modal</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Viverra accumsan in nisl nisi scelerisque eu ultrices vitae auctor. Quis vel eros donec ac. Mauris pellentesque
pulvinar pellentesque habitant morbi tristique senectus.
</p>
</Modal>
</div>
)
}
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>
.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Web site created using create-react-app" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<div id="modal-portal" />
</body>
</html>
Within a page or a component, you can now add and use the Modal.
import React, { useState } from 'react'
import { Modal } from 'codn'
function App() {
const [toggleModal, setToggleModal] = useState(false)
return (
<div className='App'>
{/* Modal Toggle Button */}
<button onClick={() => setToggleModal((prev) => !prev)} className='bg-red-9 px-20px py-10px rounded-10px hover:bg-red-7'>
Toggle Modal
</button>
{/* Modal */}
<Modal toggle={toggleModal} setToggle={setToggleModal}>
<Modal.Header className='sans font-900 text-30px fade-in-left animation-duration-500ms animation-forwards'>
<h3>👋 Hi, I'm your modal</h3>
</Modal.Header>
<Modal.Body className='sans font-400 text-15px text-gray fade-in animation-duration-800ms animation-forwards'>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Viverra accumsan in nisl nisi scelerisque eu ultrices vitae auctor. Quis vel eros donec ac. Mauris
pellentesque pulvinar pellentesque habitant morbi tristique senectus.
</p>
</Modal.Body>
<Modal.Footer className='sans font-400 text-10px'>
<h3>copyright</h3>
</Modal.Footer>
</Modal>
</div>
)
}
export 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.
import React, { useState } from 'react'
import { Input, TextArea } from 'codn'
// if you want to use the greencss classNames:
import 'greencss/css/greencss.css'
export default function AccordionComponent() {
const [password, setPassword] = useState('')
const [message, setMessage] = useState('')
return (
<div className='sans m-auto bg-gray-10 w-60rem rounded-20px shadow-small-gray-9'>
// Specify your desired width
<div className='w-50rem m-auto py-50px'>
<Input
required={true}
id='password-field'
minlength={8}
maxLength={64}
value={password}
setValue={setPassword}
type='password'
htmlFor='password'
label='Your Password'
/>
<TextArea
maxLength={500}
id='message'
label='Message'
type='text'
value={message}
setValue={setMessage}
htmlFor='message'
/>
</div>
</div>
)
}
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 |
import React from 'react'
import { CookieBanner } from 'codn'
// if you want to use the greencss classNames:
import 'greencss/css/greencss.css'
export default function CookieComponent() {
return (
<>
<CookieBanner position='top-right' shadow={false} header='greenCSS uses Cookies' buttonText='I want!'>
<p className='text-15px text-gray'>
Click “Accept” to enable greenCSS to use cookies in order to personalize this site for you. In this process you agree to
the storing of cookies and/or data in your local storage. You agree, that we use analytics to enhance site navigation
and analyze site usage. It helps us to improve the UI/UX experience for you.
</p>
</CookieBanner>
</>
)
}
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 |
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.
import React, { useState } from 'react'
import { handleShowToast, Toast } from 'codn'
// if you want to use the greencss classNames:
import 'greencss/css/greencss.css'
export default function ToastComponent() {
const [toastList, setToastList] = useState([])
return (
<>
<button onClick={() => handleShowToast('info', 'Success', 'You did it! codn toast works successfully!', setToastList)}>
Show warning
</button>
<Toast
toastList={toastList}
setToastList={setToastList}
duration={5000}
position='top-right'
progressColor='from-blue to-magenta gradient-to-left'
/>
</>
)
}
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:
const [toastList, setToastList] = useState([])
...
<button onClick={() => handleShowToast('info', 'Information Header', 'You did it! The info text appears!', setToastList)}>
Show information toast
</button>
...
<Toast
...
/>
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.
import React, { useState } from 'react'
import { Captcha } from 'codn'
export default function CaptchaComponent() {
const [captcha, setCaptcha] = useState()
// check your console!
console.log(captcha)
return (
<>
<Captcha setWord={setCaptcha} />
</>
)
}
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:
[
'build',
'chore',
'ci',
'docs',
'feat',
'fix',
'perf',
'refactor',
'revert',
'style',
'test'
];
FAQs
Sustainable and lightweight react components based on the greenCSS style guide. SSR ready.
We found that codn demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.