Skip to content
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

Merged
merged 17 commits into from
Jan 17, 2023

Conversation

frankie303
Copy link
Contributor

@frankie303 frankie303 commented Jan 11, 2023

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:

  • by using generics, added TS support to Grid's Row, Col and Container components 🔮 (BREAKING CHANGE). You can see how it works now and how was that before, in the videos below:
Before After
Screen.Recording.2023-01-12.at.13.10.38.mov
Screen.Recording.2023-01-12.at.08.55.31.mov
  • added tests

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Documentation 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 issues
  • npm run test - to run unit tests
  • npm run test:sh:docker - to run screenshot tests, detail instruction

New Feature / Bug Fix

  • Run unit tests to ensure all existing tests are still passing.
  • Add new passing unit tests to cover the code introduced by your pr.

Thanks for contributing!

@github-actions
Copy link

Compiled a new version demo.

@coveralls
Copy link

coveralls commented Jan 11, 2023

Pull Request Test Coverage Report for Build 3912632805

  • 16 of 16 (100.0%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.04%) to 97.797%

Totals Coverage Status
Change from base Build 3911817030: 0.04%
Covered Lines: 918
Relevant Lines: 921

💛 - Coveralls

@github-actions
Copy link

github-actions bot commented Jan 11, 2023

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements 99.5% 1002/1007
🟢 Branches 89.72% 192/214
🟢 Functions 98.36% 60/61
🟢 Lines 99.67% 918/921
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟢
... / Container.tsx
100% 100% 100% 100%

Test suite run success

250 tests passing in 37 suites.

Report generated by 🧪jest coverage report action from 3d85b4a

@github-actions
Copy link

Compiled a new version demo.

@github-actions
Copy link

Compiled a new version demo.

@github-actions
Copy link

Compiled a new version demo.

@mwagdi mwagdi marked this pull request as ready for review January 11, 2023 14:22
@frankie303 frankie303 marked this pull request as draft January 11, 2023 15:05
@frankie303 frankie303 added the work in progress This is a work in progress label Jan 11, 2023
@frankie303 frankie303 changed the title feat(container): add container component feat(grid): add container component Jan 11, 2023
@github-actions
Copy link

Compiled a new version demo.

@github-actions
Copy link

Compiled a new version demo.

@frankie303 frankie303 marked this pull request as ready for review January 13, 2023 15:22
@frankie303 frankie303 removed the work in progress This is a work in progress label Jan 13, 2023
@frankie303 frankie303 requested review from emrahsemizheycar and removed request for emrahsemizheycar January 13, 2023 15:22
Comment on lines -49 to +50
Component?: keyof JSX.IntrinsicElements;
component?: E;
Copy link
Contributor Author

@frankie303 frankie303 Jan 13, 2023

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

Copy link
Contributor

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

@github-actions
Copy link

Compiled a new version demo.

hcafaq

This comment was marked as resolved.

Copy link
Contributor

@lucasmaffazioli lucasmaffazioli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small notes:

Comment on lines -49 to +50
Component?: keyof JSX.IntrinsicElements;
component?: E;
Copy link
Contributor

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'>({
Copy link
Contributor

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> = {
Copy link
Contributor

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'>({
Copy link
Contributor

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

@lucasmaffazioli
Copy link
Contributor

Another thing, is it expected for the snapshots/screenshots to have changed position?

@esraltintas
Copy link
Contributor

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.

@lucasmaffazioli
Copy link
Contributor

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
}) => {

@lucasmaffazioli
Copy link
Contributor

Like we've also talked, we were having problems with Storybook showing our props, so I'll approve as it is. 🚀

@esraltintas esraltintas merged commit 9eb07f3 into main Jan 17, 2023
@esraltintas esraltintas deleted the feat/HEYUI-220-container-component branch January 17, 2023 15:05
supcar pushed a commit that referenced this pull request Jan 17, 2023
# [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]>
@supcar
Copy link
Collaborator

supcar commented Jan 17, 2023

🎉 This PR is included in version 4.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants