Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8850dcb
All component extracted
sumohammed Apr 15, 2022
e7dd815
Storybook setup
sumohammed Apr 15, 2022
8c7dbf8
Removed initial tests
sumohammed Apr 17, 2022
c6edabe
Stable storybook config
sumohammed Apr 17, 2022
de78ceb
Stable storybook config
sumohammed Apr 17, 2022
2656cac
Add inital component stories
sumohammed Apr 17, 2022
9813f7e
Update to components styles
sumohammed Apr 17, 2022
f486715
Update to components
sumohammed Apr 17, 2022
1bddc36
Added and refactored declarations file from spotlight
sumohammed Apr 17, 2022
3c4fcdd
Add styles
sumohammed Apr 17, 2022
b7a37fd
Add index.ts
sumohammed Apr 17, 2022
bc750f5
Remove Select.scss
sumohammed Apr 17, 2022
cbcb0b3
Update README.md
sumohammed Apr 17, 2022
42dadee
Updated components
sumohammed Apr 26, 2022
914cdce
Remove comments
sumohammed Apr 26, 2022
3bd483e
Move declarations.d.ts
sumohammed Apr 26, 2022
e5592ff
Update hooks
sumohammed Apr 26, 2022
cca8e6c
Update packages
sumohammed Apr 26, 2022
da10cac
Update rollup config for css modules build
sumohammed Apr 26, 2022
d8e5c0b
Update utils
sumohammed Apr 26, 2022
1cfb57b
Add .pcss.d.ts for each postcss file
sumohammed Apr 26, 2022
7f04cb2
Add .pcss.d.ts for each postcss file
sumohammed Apr 26, 2022
36f8414
Merge branch 'component_extraction' of github.com:RebelCode/react-lib…
sumohammed Apr 26, 2022
454f068
Add some interactive tests
sumohammed Apr 28, 2022
4bf9a8e
React testing library & jest setup
sumohammed May 2, 2022
fed799b
Add snaptshot test plus restructured tests in folders
sumohammed May 2, 2022
f9529d2
Removed all .pcss.d.ts files
sumohammed May 8, 2022
11e3a59
Removed all .pcss.d.ts
sumohammed May 8, 2022
5e7f2dd
Removed writeDefinitions option which creates .pcss.d.ts files
sumohammed May 8, 2022
25f81ba
Update SB config
sumohammed May 8, 2022
adfd426
Update tests
sumohammed May 9, 2022
30f1349
Extract new components with tests
sumohammed May 9, 2022
15c786f
Update ts config
sumohammed May 9, 2022
9465f68
Add icons
sumohammed May 9, 2022
cca2bd7
Add splitArray func to utils
sumohammed May 9, 2022
6b7481b
Minor Update to tests
sumohammed May 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const path = require("path");

module.exports = {
stories: ["../components/**/*.stories.@(js|jsx|ts|tsx)"],
addons: [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-interactions",
],
features: {
interactionsDebugger: true,
},
framework: "@storybook/react",
webpackFinal: async (config, { configType }) => {
// Make whatever fine-grained changes you need
// config.module.rules.push({
// test: /\.scss$/,
// use: ["style-loader", "css-loader", "sass-loader"],
// include: path.resolve(__dirname, "../"),
// });

config.module.rules.push({
test: /\.pcss$/,
use: [
"style-loader",
{
loader: "css-loader",
options: {
modules: {
localIdentName: "[name]__[local]",
},
importLoaders: 1,
},
},
"sass-loader",
],
include: path.resolve(__dirname, "../"),
});

// Return the altered config
return config;
},
};
9 changes: 9 additions & 0 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const parameters = {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
}
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# RebelCode React Library

A library of React components, hooks, and other utilities that are used in RebelCode's projects.

## Setup
To install packages, run [ for best results use yarn ]
- yarn

To start storybook, run
- yarn storybook

To build package, run [ cmd throws some errors which is currently being worked on ]
- yarn build
7 changes: 7 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
presets: [
['@babel/preset-env', {targets: {node: 'current'}}],
'@babel/preset-react',
'@babel/preset-typescript',
],
};
1 change: 0 additions & 1 deletion components/.gitkeep

This file was deleted.

213 changes: 213 additions & 0 deletions components/Alert/Alert.pcss
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
.message {
align-items: stretch;
justify-content: center;
position: relative;
padding: 5px 7px;
line-height: 18px;
font-size: 13px;
background: #fff;
border: 1px solid;
border-radius: 3px;

&:not(:first-child) {
margin-top: 10px;
}

&:not(:last-child) {
margin-bottom: 10px;
}
}

.centered {
padding: 5px 25px;
}

.shaking {
animation-name: shake-animation;
animation-duration: 0.2s;
}

.dashicon {
width: 16px !important;
height: 16px !important;
font-size: 16px !important;
line-height: 16px !important;
margin-top: 1px;
}

.icon {
composes: dashicon;
margin-right: 8px;
flex-grow: 0;
flex-shrink: 0;
}

.logo {
composes: icon;

& img {
width: 18px;
height: 18px;
max-width: unset;
}
}

.content {
display: block;
}

.dismiss-btn {
position: absolute;
top: 5px;
right: 7px;
color: #333;
padding: 0 !important;
border: 0;
border-radius: 100px;
background: transparent;
box-sizing: border-box;
opacity: 0.5;

&:hover {
opacity: 1;
}

&:focus-visible {
box-shadow: 0 0 0 1px currentColor;
}

& :global(.dashicon) {
transform: translateX(1px);
}
}


@keyframes shake-animation {
0%, 20%, 40%, 60%, 80%, 100% {
transform: translateX(0);
}
30%, 70% {
transform: translateX(-2px);
}
10%, 50%, 90% {
transform: translateX(2px);
}
}

/*
* COLOR VARIATIONS
*----------------------------
*/

/* SUCCESS */
.success {
composes: message;
background: #ecf4eb;
box-shadow: 0 1px 2px rgba(37, 85, 31, 0.15);
border-color: rgba(61, 142, 52, 0.4);

& .icon, & .dismiss-btn {
color: #2e6b27;
}

& .content {
color: #122b10;
}
}

/* INFO */
.info {
composes: message;
background: #e8f5f7;
box-shadow: 0 1px 2px rgba(14, 91, 107, 0.15);
border-color: rgba(24, 152, 178, 0.4);

& .icon, & .dismiss-btn {
color: #127286;
}

& .content {
color: #072e35;
}
}

/* WARNING */
.warning {
composes: message;
background: #fff4e6;
box-shadow: 0 1px 2px rgba(153, 88, 0, 0.15);
border-color: rgba(255, 147, 0, 0.4);

& .icon, & .dismiss-btn {
color: #bf6e00;
}

& .content {
color: #4d2c00;
}
}

/* PREMIUM */
.premium {
composes: message;
background: rgba(221, 35, 75, .1);
border-color: var(--sli-pro);

& .icon, & .dismiss-btn, & .content {
color: var(--sli-quasi-black);
}

& a {
color: #000 !important;
font-weight: 600;
}
}

/* PRO TIP */
.pro-tip {
composes: message;
background: #eeeffa;
box-shadow: 0 1px 2px rgba(53, 57, 123, 0.15);
border-color: rgba(89, 95, 205, 0.4);

& .icon, & .dismiss-btn {
color: #43479a;
}

& .content {
color: #1b1d3e;
}
}

/* ERROR */
.error {
composes: message;
background: #fbe9ec;
box-shadow: 0 1px 2px rgba(130, 22, 40, 0.15);
border-color: rgba(216, 36, 66, 0.4);

& .icon, & .dismiss-btn {
color: #a21b32;
}

& .content {
color: #410b14;
}
}


/* GREY */
.grey {
composes: message;
background: var(--sli-wp-grey);
box-shadow: 0 1px 2px rgba(120, 120, 120, 0.15);
border-color: var(--sli-line-color);

& .icon, & .dismiss-btn {
color: #555;
}

& .content {
color: #222;
}
}
89 changes: 89 additions & 0 deletions components/Alert/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import React, { CSSProperties, ReactNode } from "react";
import css from "./Alert.pcss";
import { classList } from "../../utils/classes";
import { Dashicon, DashiconTy } from "../Dashicon";

type AlertType =
| "success"
| "info"
| "pro-tip"
| "premium"
| "warning"
| "error"
| "grey";

export type Props = {
className?: string;
style?: CSSProperties;
children?: ReactNode;
type: AlertType;
showIcon?: boolean;
shake?: boolean;
centered?: boolean;
isDismissible?: boolean;
onDismiss?: () => void;
};

export function Alert({
className,
style,
children,
type,
showIcon,
shake,
centered,
isDismissible,
onDismiss,
}: Props) {
const [dismissed, setDismissed] = React.useState(false);

const handleClick = () => {
if (isDismissible) {
setDismissed(true);
onDismiss && onDismiss();
}
};

const fullClassName = classList(
css[type],
(shake && css.shaking||""),
( centered && css.centered||""),
className as string
);

return dismissed ? null : (
<div className={fullClassName} style={style} aria-label="Alert">
{showIcon && (
<Dashicon className={css.icon} icon={getIconFor(type)} />
)}

<div className={css.content}>{children}</div>

{isDismissible && (
<button className={css.dismissBtn} onClick={handleClick}>
<Dashicon icon="no" className={css.dashicon} />
</button>
)}
</div>
);
}

/**
* Retrieves the appropriate dashicon for a given message type.
*
* @param type
*/
function getIconFor(type: AlertType): DashiconTy {
switch (type) {
case "success":
return "yes-alt";
case "pro-tip":
return "lightbulb";
case "error":
case "warning":
return "warning";
case "info":
default:
return "info";
}
}
Loading