Skip to content

Commit f777629

Browse files
author
Administrator
committed
initial 1.0.0
0 parents  commit f777629

40 files changed

+3204
-0
lines changed

.eslintrc.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
module.exports = {
2+
"env": {
3+
"browser": true,
4+
"es2021": true
5+
},
6+
"extends": [
7+
"eslint:recommended",
8+
"plugin:react/recommended",
9+
"plugin:@typescript-eslint/recommended"
10+
],
11+
"overrides": [
12+
],
13+
"parser": "@typescript-eslint/parser",
14+
"parserOptions": {
15+
"ecmaVersion": "latest",
16+
"sourceType": "module"
17+
},
18+
"plugins": [
19+
"react",
20+
"@typescript-eslint"
21+
],
22+
"rules": {
23+
"indent": [
24+
"error",
25+
"tab"
26+
],
27+
"linebreak-style": [
28+
"error",
29+
"unix"
30+
],
31+
"quotes": [
32+
"error",
33+
"double"
34+
],
35+
"semi": [
36+
"error",
37+
"always"
38+
],
39+
"object-curly-spacing": ["error", "always"],
40+
},
41+
};

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.npmrc
2+
node_modules/
3+
# build/
4+
storybook-static/
5+
yarn.lock

.storybook/main.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const path = require("path");
2+
3+
module.exports = {
4+
stories: ["../src/**/*.stories.tsx"],
5+
// Add any Storybook addons you want here: https://storybook.js.org/addons/
6+
addons: ['@storybook/addon-controls','@storybook/addon-essentials','storybook-dark-mode'],
7+
webpackFinal: async config => {
8+
config.module.rules.push({
9+
test: /\.(less)$/,
10+
use: ["style-loader", "css-loader", "less-loader"],
11+
include: path.resolve(__dirname, "../")
12+
});
13+
config.module.rules.push({
14+
test: /\.(ts|tsx)$/,
15+
loader: require.resolve("babel-loader"),
16+
options: {
17+
presets: [["react-app", {
18+
flow: false,
19+
typescript: true
20+
}]]
21+
}
22+
});
23+
config.resolve.extensions.push(".ts", ".tsx", ".less");
24+
return config;
25+
},
26+
core: {
27+
builder: "@storybook/builder-webpack5"
28+
}
29+
};

.storybook/preview.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/**
2+
* Read https://storybook.js.org/docs/react/configure/overview#configure-story-rendering
3+
* for more information about the purpose of this file.
4+
*
5+
* Use preview.js for global code (such as CSS imports or JavaScript mocks)
6+
* that applies to all stories. For example, `import thirdPartyCss.css`.
7+
*
8+
* This file can have three exports:
9+
* - decorators - an array of global decorators
10+
* - parameters - an object of global parameters
11+
* - globalTypes - definition of globalTypes
12+
*/
13+
14+
/**
15+
* Decorators
16+
*
17+
* A decorator is a way to wrap a story in extra “rendering” functionality.
18+
*
19+
* Example:
20+
*
21+
* import React from 'react';
22+
* export const decorators = [(Story) => <div style={{ margin: '3em' }}><Story/></div>];
23+
*
24+
* Each story throughout the library will be wrapped in a div with a margin of 3
25+
*/
26+
27+
export const decorators = [(Story) => <div style={{ overflow:"hidden" }}><Story/></div>];
28+
29+
/**
30+
* Parameters
31+
*
32+
* Most Storybook addons are configured via a parameter-based API.
33+
* You can set global parameters in this file
34+
*
35+
* export const parameters = {
36+
* backgrounds: {
37+
* values: [
38+
* { name: 'red', value: '#f00' },
39+
* { name: 'green', value: '#0f0' },
40+
* ],
41+
* },
42+
* };
43+
*
44+
* With backgrounds, you configure the list of backgrounds that every story can render in.
45+
*/
46+
47+
/**
48+
* Global Types
49+
*
50+
* Global Types allow you to add your own toolbars by creating
51+
* globalTypes with a toolbar annotation:
52+
*
53+
* For example:
54+
*
55+
*
56+
* export const globalTypes = {
57+
* theme: {
58+
* name: 'Theme',
59+
* description: 'Global theme for components',
60+
* defaultValue: 'light',
61+
* toolbar: {
62+
* icon: 'circlehollow',
63+
* // array of plain string values or MenuItem shape
64+
* items: ['light', 'dark'],
65+
* },
66+
* },
67+
* };
68+
*
69+
* Will add a new dropdown in your toolbar with options light and dark.
70+
**/
71+
72+
/*
73+
export const globalTypes = {
74+
theme: {
75+
name: 'Theme',
76+
description: 'Global theme for components',
77+
defaultValue: 'light',
78+
toolbar: {
79+
icon: 'circlehollow',
80+
// array of plain string values or MenuItem shape
81+
items: ['light', 'dark'],
82+
},
83+
},
84+
};
85+
*/
86+
87+
88+
export const parameters = {
89+
darkMode: {
90+
// Set the initial theme
91+
// current: 'light',
92+
darkClass:"dark",
93+
lightClass:"light",
94+
classTarget:'html',
95+
stylePreview:true,
96+
},
97+
};
98+

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Harvey Delaney
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
### React Component Library - code4bones react UI
2+
3+
### Components
4+
5+
| Component| Description |
6+
| ------------ | ------------ |
7+
| TreeMenu | Navigation Menu Tree |
8+
9+
10+
# react-c4b-ui
11+
12+
![npm](https://img.shields.io/npm/v/@code4bones/react-c4b-ui?label=latest)
13+
![npm](https://img.shields.io/npm/dt/@code4bones/react-c4b-ui?style=flat-square&label=installs)
14+
15+
![](https://img.shields.io/github/downloads/code4bones/react-c4b-ui/total) ![](https://img.shields.io/github/watchers/code4bones/react-c4b-ui) ![](https://img.shields.io/github/forks/code4bones/react-c4b-ui) ![](https://img.shields.io/github/release/code4bones/react-c4b-ui) ![](https://img.shields.io/github/issues/code4bones/react-c4b-ui)
16+
17+
### Links
18+
19+
[Change log](https://github.com/code4bones/react-c4b-ui/wiki/Change-Log "Change log")
20+
21+
### System default / custom theme
22+
23+
![sample](https://github.com/code4bones/react-c4b-ui/blob/master/img/theme.png?raw=true "sample")
24+
25+
|feature|sample|
26+
|-------|------|
27+
|![cap](https://github.com/code4bones/react-c4b-ui/blob/master/img/items_reveal.gif?raw=true)| |
28+
![cap](https://github.com/code4bones/react-c4b-ui/blob/master/img/rorate_group.gif?raw=true)|![cap](https://github.com/code4bones/react-c4b-ui/blob/master/img/static_group.gif?raw=true)|
29+
30+
### Install
31+
32+
33+
`$ yarn add @code4bones/react-c4b-ui`
34+
35+
#### TreeMenu
36+
37+
#### Brief
38+
39+
```tsx
40+
41+
import {TreeMenu, TreeMenuActions,TreeMenuItem } from "@code4bones/react-c4b-ui";
42+
import "@code4bones/react-c4b-ui/build/styles.css";
43+
44+
const ITEMS : TreeMenuItem[] = [{
45+
id:"item1",
46+
title:"Item 1",
47+
// other TreeMenuItem's props
48+
childs:[{
49+
id:"sub",
50+
title:"Subitem 1",
51+
}]
52+
}];
53+
54+
// if your need to use exponsed actions
55+
const ref = createRef<TreeMenuActions>();
56+
57+
<TreeMenu
58+
ref={ref}
59+
items={ITEMS}
60+
onClick={onClick}
61+
/>
62+
63+
```
64+
65+
### Properties
66+
67+
type `RenderFn` = (item:MenuItem) => React.ReactElement | undefined | null;
68+
type `RenderType` = `RenderFn` | React.ReactElement;
69+
70+
71+
| Propery name | Description | Signature
72+
| ------------- | ------------------------------ | ---- |
73+
| `items[]` | tree menu items array | `TreeMenuItem`[] |
74+
| `ref` | handle to TreeMenu methods | `TreeMenuActions` |
75+
| `onClick` | item click handler | onClick?:(item:TreeMenuItem) => void|
76+
| `onToggle` | collapse / expand | onToggle?:(id?:string,collapsed?:boolean) => void;|
77+
| `initialCollapsed` | initial tree state | boolean |
78+
| `initialSelected` | initial selected item | item's `id` : string|
79+
| `renderBadge` | item click handler | `RenderType` |
80+
| `renderIcon` | Left side element of item | `RenderType` |
81+
| `renderGroupState` | Group indicator | `RenderType` |
82+
| `theme` | theme override class name | `dark`, `light`, custom name |
83+
| `classPrefix` | container global prefix | string |
84+
| `enableRotate` | Rotate collapse / expand | boolean |
85+
86+
87+
`TreeMenuItem`
88+
89+
```tsx
90+
id:string;
91+
title:string | React.ReactElement;
92+
info?:string | React.ReactElement;
93+
infoReveal?:InfoReveal;
94+
icon?:React.ReactElement;
95+
badge?:string | React.ReactElement;
96+
disabled?:boolean;
97+
unselectable?:boolean;
98+
titleClass?:string;
99+
infoClass?:string;
100+
style?:React.CSSProperties;
101+
titleStyle?:React.CSSProperties;
102+
infoStyle?:React.CSSProperties;
103+
```
104+
105+
`TreeMenuActions` ( use `ref` )
106+
```
107+
enable:(id:string,disable?:boolean) => void;
108+
getItem:(id:string) => TreeMenuItem | null;
109+
collapse:(id:string,collapsed?:boolean) => void;
110+
select:(id:string) => void;
111+
112+
```
113+
114+
### Sample
115+
116+
Sample available via storybook `yarn storybook`

build/TreeMenu/TreeMenu.d.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React from "react";
2+
import { TreeMenuItem } from "./TreeMenu.types";
3+
import "./TreeMenu.less";
4+
export { TreeMenuItem };
5+
export declare type TreeMenuActions = {
6+
enable: (id: string, disable?: boolean) => void;
7+
getItem: (id: string) => TreeMenuItem | null;
8+
collapse: (id: string, collapsed?: boolean) => void;
9+
select: (id: string) => void;
10+
invalidate: () => void;
11+
rebuild: (items: TreeMenuItem[]) => void;
12+
};
13+
declare const TreeMenu: React.ForwardRefExoticComponent<{
14+
items: TreeMenuItem[];
15+
theme?: string;
16+
itemHeight?: number;
17+
classPrefix?: string;
18+
initialCollapsed?: boolean;
19+
initialSelected?: string;
20+
onClick?: (id: string) => void;
21+
onToggle?: (id?: string, collapsed?: boolean) => void;
22+
} & {
23+
treeID: string;
24+
infoReveal?: "always" | "vertical" | "horizontal";
25+
titleStyle?: React.CSSProperties;
26+
infoStyle?: React.CSSProperties;
27+
enableRotate?: boolean;
28+
badgeVisible?: boolean;
29+
groupIconLeft?: boolean;
30+
renderBadge?: import("./TreeMenu.types").RenderType;
31+
renderIcon?: import("./TreeMenu.types").RenderType;
32+
renderGroupState?: import("./TreeMenu.types").RenderType;
33+
propertyGrid?: boolean;
34+
} & React.RefAttributes<TreeMenuActions>>;
35+
export default TreeMenu;

0 commit comments

Comments
 (0)