-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(grid): add container component #128
Conversation
Compiled a new version demo. |
Pull Request Test Coverage Report for Build 3912632805
💛 - Coveralls |
Coverage report
Show new covered files 🐣
Test suite run success250 tests passing in 37 suites. Report generated by 🧪jest coverage report action from 3d85b4a |
Compiled a new version demo. |
Compiled a new version demo. |
Compiled a new version demo. |
…eat/HEYUI-220-container-component
Compiled a new version demo. |
Compiled a new version demo. |
…eat/HEYUI-220-container-component
Component?: keyof JSX.IntrinsicElements; | ||
component?: E; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO
: I think we should adjust other polymorphic components as well in a separate PR with this logic/change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, Pagination will also use something similar
Compiled a new version demo. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small notes:
Component?: keyof JSX.IntrinsicElements; | ||
component?: E; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, Pagination will also use something similar
|
||
import styles from './Container.module.css'; | ||
|
||
function Container<E extends React.ElementType = 'div'>({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe C could represent container
(also in Container.types.ts
)?.
ElementType = 'div'
could possibly be moved to the types file?
Another possible way to simplify a bit and transfer the typing logic to just one place, something like this could be done:
export interface PropsBasedOnComponent<T> {
<C extends React.ElementType = 'div'>(
props: {
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component?: C;
} & T &
Omit<React.ComponentPropsWithoutRef<C>, keyof T>,
): JSX.Element | null;
}
const Container: PropsBasedOnComponent<ContainerProps> = ({
component,
...rest
}) => {
@@ -0,0 +1,13 @@ | |||
import React from 'react'; | |||
|
|||
type ContainerBaseProps<E extends React.ElementType> = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very very nice typings \o/
@@ -8,8 +8,8 @@ import { RowProps } from './Row.types'; | |||
import guttersStyles from '../styles/gutters.module.css'; | |||
import styles from './Row.module.css'; | |||
|
|||
function Row({ | |||
Component = 'div', | |||
function Row<E extends React.ElementType = 'div'>({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing applies here, but like you've said on the PR we could have a proper PR to then unify this type of logic
Another thing, is it expected for the snapshots/screenshots to have changed position? |
Hi @lucasmaffazioli Yes, It was effecting the other component, when we put the padding in root, with this pr, we will have padding just for the grid. |
Here's how we've done in our call: /**
* `PropsBasedOnComponent` - This interface inherits props from a designated component C through ref
*/
export interface PropsBasedOnComponent<
ComponentBaseProps,
DefaultElement extends React.ElementType,
> {
<Component extends React.ElementType = DefaultElement>(
props: {
/**
* The component used for the root node.
* Either a string to use a HTML element or a component.
*/
component?: Component;
} & ComponentBaseProps &
Omit<React.ComponentPropsWithoutRef<Component>, keyof ComponentBaseProps>,
): JSX.Element | null;
}
export const PaginationItem: PropsBasedOnComponent<
PaginationItemProps,
'a'
> = ({
page,
isCurrentPage,
isDisabled,
type,
onClick,
component = 'a',
...rest
}) => { |
Like we've also talked, we were having problems with Storybook showing our props, so I'll approve as it is. 🚀 |
# [4.0.0](v3.3.1...v4.0.0) (2023-01-17) ### Features * **grid:** add container component ([#128](#128)) ([9eb07f3](9eb07f3)) ### BREAKING CHANGES * **grid:** `Component` prop is renamed as `component` for grid Row, Column and Container * docs(grid): add default value in docs * feat: adjust row widths * revert(grid): remove nested grid styles * test: update screenshot tests * chore: run npm install Co-authored-by: mwagdi <[email protected]>
🎉 This PR is included in version 4.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Pull Request
Description
JIRA ticket: https://heycar.atlassian.net/browse/HEYUI-220
With this PR, we introduced polymorphic Container component to our Grid package. Besides that:
Row
,Col
andContainer
components 🔮 (BREAKING CHANGE). You can see how it works now and how was that before, in the videos below:Screen.Recording.2023-01-12.at.13.10.38.mov
Screen.Recording.2023-01-12.at.08.55.31.mov
Type of change
How do I test this
Checklist
Did you remember to take care of the following?
npm i
– for new NPM dependencies.npm run lint
- to check for linting issuesnpm run test
- to run unit testsnpm run test:sh:docker
- to run screenshot tests, detail instructionNew Feature / Bug Fix
Thanks for contributing!