generated from abelflopes/lerna-monorepo-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ea4130
commit a27d7ac
Showing
22 changed files
with
369 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# RCK | React Grid Component | ||
|
||
The React Grid component features a robust 12-column system, providing developers with a flexible framework to create responsive and well-structured layouts. This system allows elements to be precisely positioned within the grid, offering granular control over their placement and alignment. With the ability to utilize these 12 columns, developers can design layouts that are visually balanced and optimized for different screen sizes. | ||
|
||
Moreover, the React Grid component offers the convenience of both wrapping and nowrap behaviors. When set to wrap, the grid intelligently adjusts its content, allowing items to flow into new rows as needed. This ensures that the layout gracefully accommodates varying amounts of content without sacrificing its structure. Conversely, the nowrap option prevents items from wrapping onto new lines, maintaining a compact and streamlined appearance. | ||
|
||
By combining the 12-column system with the flexibility to wrap or nowrap elements, developers can effortlessly create responsive designs that adapt to diverse devices and content lengths. This versatile component empowers developers to craft visually appealing interfaces that maintain consistency and readability across different screen sizes, enhancing the overall user experience. | ||
|
||
### Installation | ||
|
||
To integrate the this component into your React apps, you can install it using npm or yarn: `npm i --save @react-ck/grid` or `yarn add @react-ck/grid`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
extends: "@react-ck/babel-config", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
declare module "*.module.scss" { | ||
const content: Record<string, string>; | ||
export default content; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Hack for module resolution of non built packages | ||
export * from "./src/index"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { config as default } from "@react-ck/jest-config"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "@react-ck/grid", | ||
"private": false, | ||
"version": "1.0.0", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"/dist" | ||
], | ||
"homepage": "https://github.com/abelflopes/react-ck/tree/master/packages/components/banner#readme", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/abelflopes/react-ck.git" | ||
}, | ||
"scripts": { | ||
"build": "NODE_ENV=production webpack", | ||
"lint:typescript": "tsc --noEmit", | ||
"test": "npx -y npm-run-all -s test:*", | ||
"test:unit": "jest --testPathPattern=\".unit.*\"", | ||
"test:snapshot": "jest --testPathPattern=\".snapshot.*\"", | ||
"test:snapshot:update": "jest --testPathPattern=\".snapshot.*\" -u" | ||
}, | ||
"devDependencies": { | ||
"@react-ck/babel-config": "^1.0.0", | ||
"@react-ck/jest-config": "^1.0.0", | ||
"@react-ck/typescript-config": "^1.0.0", | ||
"@react-ck/webpack-config": "^1.0.0", | ||
"@types/react": "^18.2.33" | ||
}, | ||
"peerDependencies": { | ||
"react": "^18.2.0" | ||
}, | ||
"dependencies": { | ||
"@react-ck/scss-utils": "^1.0.0", | ||
"@react-ck/theme": "^1.0.0", | ||
"classnames": "^2.3.2" | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/components/grid/specs/__snapshots__/index.snapshot.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Snapshot GridColumn renders correctly 1`] = ` | ||
<div | ||
className="root size_auto" | ||
style={ | ||
{ | ||
"--columns": 0, | ||
"--size": "auto", | ||
} | ||
} | ||
/> | ||
`; | ||
|
||
exports[`Snapshot GridContainer renders correctly 1`] = ` | ||
<div | ||
className="root wrap" | ||
/> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from "react"; | ||
import { GridContainer, GridColumn } from "../src/index"; | ||
import renderer from "react-test-renderer"; | ||
|
||
describe("Snapshot GridContainer", () => { | ||
test("renders correctly", async () => { | ||
const tree = renderer.create(<GridContainer />).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
describe("Snapshot GridColumn", () => { | ||
test("renders correctly", async () => { | ||
const tree = renderer.create(<GridColumn />).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from "react"; | ||
import { GridContainer, GridColumn } from "../src/index"; | ||
import { render, screen } from "@testing-library/react"; | ||
import "@testing-library/jest-dom"; | ||
|
||
describe("Unit GridContainer", () => { | ||
test("renders correctly", async () => { | ||
render(<GridContainer data-testid="container" />); | ||
const find = await screen.findByTestId("container"); | ||
expect(find).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
describe("Unit GridColumn", () => { | ||
test("renders correctly", async () => { | ||
render(<GridColumn data-testid="column" />); | ||
const find = await screen.findByTestId("column"); | ||
expect(find).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React, { useEffect } from "react"; | ||
import styles from "./styles/column.module.scss"; | ||
import classNames from "classnames"; | ||
import { useGridContext } from "./context"; | ||
|
||
export interface GridColumnProps extends React.HTMLAttributes<HTMLHRElement> { | ||
size?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | "auto"; | ||
} | ||
|
||
export const GridColumn = ({ | ||
size = "auto", | ||
className, | ||
style, | ||
...otherProps | ||
}: Readonly<GridColumnProps>): React.ReactElement => { | ||
const { columnsCount, registerColumn } = useGridContext(); | ||
|
||
useEffect(() => { | ||
const deregisterColumn = registerColumn(); | ||
|
||
return deregisterColumn; | ||
}, [registerColumn]); | ||
|
||
return ( | ||
<div | ||
style={{ | ||
...style, | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions | ||
...({ "--size": size, "--columns": columnsCount } as React.CSSProperties), | ||
}} | ||
className={classNames( | ||
styles.root, | ||
{ | ||
[`${styles.size_auto}`]: size === "auto", | ||
}, | ||
className, | ||
)} | ||
{...otherProps} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React, { useCallback, useMemo, useState } from "react"; | ||
import styles from "./styles/container.module.scss"; | ||
import classNames from "classnames"; | ||
import { GridContext, type GridContextProps } from "./context"; | ||
|
||
export interface GridContainerProps extends React.HTMLAttributes<HTMLHRElement> { | ||
wrap?: boolean; | ||
} | ||
|
||
export const GridContainer = ({ | ||
wrap = true, | ||
className, | ||
...otherProps | ||
}: Readonly<GridContainerProps>): React.ReactElement => { | ||
const [columnsCount, setColumnsCount] = useState(0); | ||
|
||
const registerColumn = useCallback<GridContextProps["registerColumn"]>(() => { | ||
setColumnsCount((v) => v + 1); | ||
|
||
return () => { | ||
setColumnsCount((v) => v - 1); | ||
}; | ||
}, []); | ||
|
||
const contextValue = useMemo<GridContextProps>( | ||
() => ({ | ||
columnsCount, | ||
registerColumn, | ||
}), | ||
[columnsCount, registerColumn], | ||
); | ||
|
||
return ( | ||
<GridContext.Provider value={contextValue}> | ||
<div | ||
className={classNames( | ||
styles.root, | ||
{ | ||
[`${styles.wrap}`]: wrap, | ||
}, | ||
className, | ||
)} | ||
{...otherProps} | ||
/> | ||
</GridContext.Provider> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React, { useContext } from "react"; | ||
|
||
export interface GridContextProps { | ||
columnsCount: number; | ||
registerColumn: () => () => void; | ||
} | ||
|
||
export const themeContextDefaults: GridContextProps = { | ||
columnsCount: 0, | ||
registerColumn() { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
return () => {}; | ||
}, | ||
}; | ||
|
||
export const GridContext = React.createContext<GridContextProps>(themeContextDefaults); | ||
|
||
export const useGridContext = (): GridContextProps => useContext(GridContext); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from "./Container"; | ||
|
||
export * from "./Column"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
@import "@react-ck/theme"; | ||
@import "@react-ck/scss-utils"; | ||
|
||
.root { | ||
width: calc( | ||
(100% / 12 * var(--size)) - | ||
(#{get-css-var(grid-container, gap)} * (var(--columns) - 1) / var(--columns)) | ||
); | ||
flex-shrink: 0; | ||
flex-grow: 0; | ||
} | ||
|
||
.size_auto { | ||
flex-shrink: 1; | ||
flex-grow: 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@import "@react-ck/theme"; | ||
@import "@react-ck/scss-utils"; | ||
|
||
.root { | ||
@include define-css-var(divider, flex-wrap, none); | ||
@include define-css-var(grid-container, gap, get-spacing(2)); | ||
|
||
display: flex; | ||
gap: get-css-var(grid-container, gap); | ||
flex-wrap: get-css-var(grid-container, flex-wrap); | ||
} | ||
|
||
.wrap { | ||
@include define-css-var(grid-container, flex-wrap, wrap); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "@react-ck/typescript-config/tsconfig.build.json", | ||
"compilerOptions": { | ||
"outDir": "./dist" | ||
}, | ||
"include": ["./*.d.ts", "./src/**/*", "./src/index.ts*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "@react-ck/typescript-config/tsconfig.json", | ||
"include": ["./**/*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { getWebpackConfig } from "@react-ck/webpack-config"; | ||
import packageJson from "./package.json"; | ||
|
||
export default getWebpackConfig({ | ||
cssHashSalt: packageJson.name, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.