@twinklecube/create-ui-library

twinklecube ui - a react library to create and manage UIs...


Keywords
twinklecube, react, javascript, typescript, styled-components, react 18, react 18.3, component-library, ui-library, ui, react-component, components
License
ISC
Install
npm install @twinklecube/create-ui-library@0.1.5

Documentation

twinklecubeUI is a React ui component library

Install:

npx @twinklecube/create-ui-library ui-library required node version 18.17.0 or higher

Here the 'ui-library' is the package/directory name... so, it's your choice
This command will create a folder called 'ui-library' and install the project there
npx @twinklecube/create-ui-library .
This command will install the package in the current directory

  • React 18
  • typescript
  • css, css modules
  • scss/sass, modules
  • less, less modules
  • styled-components
  • @emotion

Run in development server:

npm start
This command will start the development server on port 3030

Build:

npm run build
This command will create the 'dist' folder and put the bundled files there

Documentation

css and modules, sass/scss and modules, less and modules as well as styled-components are enabled in default

How to create a new component

  • Create a new folder inside src > components with your component name. (eg. 'button')
  • Inside the newly created folder, create your corrensponding react file.
    (eg. Button.tsx)
    your component code goes there.

How to include your component in the twincklecube dashbord

  • Inside the component folder created previously, create the corresponding .twinklecube.tsx file (eg. Button.twinklecube.tsx)
  • Inside this file import the component file
    `import Button from './Button'`
  • Try our component with whatever the props, types, etc... you have defined.
    you can see an example component 'Chip'.
  • Inside the 'twinklecube' folder, in the SideNav component, create a new route for the newly created component
    you may follow the patters
  • Inside the 'twinklecube' folder, in the 'Container' component import the new '.twinklecube.tsx' component.
    eg. 'import ButtonTwinklecube from "../../../src/components/button/Button.twinklecube"';
    and expose the component to the route created previously
    you may follow the pattern
  • Now you are good to go!!!
    Your component is on the twinklecube dashboard

styled-components

version 5.3.6
styled-components are installed and ready to use
just import as usual and that's it
import styled from "styled-components"

@emotion

install emotion.
npm i @emotion/styled
then, just import as usual. you are good to go.
import styled from @emotion/styled

Limitations with styled-components and @emotion

if you use styled-components or @emotion in this ui-library, please be mindful, that,

  1. you upload the library to a remote repository (eg. github, bitbucket, etc...) first
  2. and then install the ui-library in to any of your intended apps from the remote repository
    eg. `npm install git+https://github.com/your-user-name/your-repo-name.git`

if you install the ui-library in another app locally
eg:
npm i ../ui-library or
npm link ui-library

you will get invalid hook call runtime error when you run your app on devServer or when you run your app through the dist folder
This seems like a wierd bug... and anyone out there is most welcome to have a look :)
npm clone https://github.com/twinklecube/create-ui-library.git

Assets - images/fonts

assets are copied in to the dist folder and NOT base64 encoded

Following formats are supported
Image formats: jpg, jpeg, svg, png, gif, webp
Font formats: woff2, woff, eot, ttf, otf

Add any other image or font format

Step 1: open webpack.config.js which is located in the root folder
Step 2: find test: /\.(jpg|jpeg|png|gif|svg|webp|woff|woff2|eot|ttf|otf)$/i
Step 4: include the new file/format extension in this list seperated by a pipe character
Step 5: open rollup.config.js which is located in the root folder
Step 6: find include : [ '**/*.svg', '**/*.png', '**/*.jp(e)?g', '**/*.gif', '**/*.webp', '**/*.woff2', '**/*.woff', '**/*.ttf', '**/*.otf', '**/*.eot' ]
Step 7: include the new file/format extension in this array seperated by a comma. eg '**/*.your-file-extension'
Step 5: open module.d.ts which is located in the src folder
Step 6: add declare module *.your-file-extension; at the end of the file.

How to use assets in your app

when this project is built, assets(images/fonts) are copied in to the dist folder.
in your app, you have to copy these assets in to the build folder (eg. dist folder) of the app in order to be referenced and served correctly
for example you can do the following in your webpack config file

const CopyPlugin = require('copy-webpack-plugin');

module.exports = {

plugins: [
    new CopyPlugin({
        patterns: [
            {
                from: path.resolve(__dirname, 'node_modules', '<your-ui-library>', 'dist', 'esm', 'images'),
                to: path.join(__dirname, 'dist', 'images'),
                noErrorOnMissing: true
            },
            {
                from: path.resolve(__dirname, 'node_modules', <your-ui-library>', 'dist', 'esm', 'fonts'),
                to: path.join(__dirname, 'dist', 'fonts'),
                noErrorOnMissing: true
            }
        ]
    })
]

}

More documentation and features will follow

Please note, that twinklecube is very new... there may be many hiccups.

please be good enough to inform us about any bugs
https://github.com/twinklecube/create-ui-library/issues