Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

feat(Props Interfaces): add props interface to Button, AccordionTitle, AccordionContent and refactoring the types definitions #130

Merged
merged 13 commits into from Aug 27, 2018

Conversation

mnajdova
Copy link
Contributor

This PR introduces props interface for the Button component, as part of #117

-added export from the lib index.ts for the NotStrictProps type
@codecov
Copy link

codecov bot commented Aug 24, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@380d586). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #130   +/-   ##
=========================================
  Coverage          ?   88.94%           
=========================================
  Files             ?       47           
  Lines             ?      778           
  Branches          ?      112           
=========================================
  Hits              ?      692           
  Misses            ?       84           
  Partials          ?        2
Impacted Files Coverage Δ
src/components/Chat/Chat.tsx 94.73% <100%> (ø)
src/components/Accordion/AccordionTitle.tsx 65% <100%> (ø)
src/components/Avatar/Avatar.tsx 91.42% <100%> (ø)
src/components/Divider/Divider.tsx 100% <100%> (ø)
src/components/Button/Button.tsx 93.93% <100%> (ø)
src/components/Accordion/Accordion.tsx 66% <100%> (ø)
src/components/Grid/Grid.tsx 100% <100%> (ø)
src/components/Accordion/AccordionContent.tsx 80% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 380d586...0d804db. Read the comment docs.

manajdov added 2 commits August 24, 2018 15:29
# Conflicts:
#	src/components/Accordion/Accordion.tsx
#	src/lib/index.ts
@miroslavstastny
Copy link
Member

I think that as part of the PR you should also use the props interface in buttonStyles.ts.

@mnajdova
Copy link
Contributor Author

That's actually a good point. Will add the interfaces in the styles as well.

@mnajdova
Copy link
Contributor Author

I added the interfaces for the props in the button as well as avatar styles as those PR was merged already. Please review now.

@@ -49,7 +50,7 @@ const getAvatarFontSize = (size: number) => {
}

const avatarStyles: IComponentPartStylesInput = {
root: ({ props: { size } }): ICSSInJSStyle => ({
root: ({ props: { size } }: { props: IAvatarProps }): ICSSInJSStyle => ({
Copy link
Contributor

Choose a reason for hiding this comment

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

seems that it is better for us to introduce general type for that as well, instead of inline type literal. Let me take a closer look to propose a suggestion

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well generally the the object that we are receiving here is {props, variables} so we may introduce this, but the thing is this is not used everywhere, in some cases we have just the props, or nothing which isn't a problem, but when we have just the pros or nothing we immediately know that this part of the styles is somewhat static and doesn't depend on any prop of variable. So I am not sure if we wan to specify specific types which may won't be used...

Copy link
Member

Choose a reason for hiding this comment

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

Should we not wait until we figure out the optimal typing pattern for styles and variables before typing them? Especially as we plan to change this signature.

We haven't yet figured out how 3rd parties will create themes, but we know they will need access to component typings as well so that they can type their styles/variables as well. Not sure what the best way to type these is but I know from testing it myself that there are several ways to go about it, each with their own pros and cons.

I would propose that PRs opened against #117 for the purpose of typing props do not also attempt to type themes, just props for now.

Copy link
Contributor

@kuzhelov kuzhelov Aug 24, 2018

Choose a reason for hiding this comment

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

lets try to follow the thought to see if we are on the same page. Seems that, at least semantically, the type of functions that are used for styling is the following (names are made up just as an example):

type StyleProvider<TProps, TVariables = any> = (args: StyleProviderArg) => ICSSInJSStyle`

type StyleProviderArg<TProps, TVariables = any> = { props: TProps, variables: TVariables }

To me it seems reasonable to declare this knowledge explicitly - because otherwise we would have the following issues for the following form:

root: ({ props: { size } }: { props: IAvatarProps }): ICSSInJSStyle =>
  • it is unclear for developer that variables parameter can be also consumed
  • an attempt to consume variables parameter will result in immediate need to change literal type. This will quickly become annoying with each new case :)
// compile-time error! type literal needs to be fixed as well
root: ({ props: { size }, variables }: { props: IAvatarProps }): ICSSInJSStyle =>
  • also an important factor that it will be much easier to read the following expression
root: ({ props: { size }}: StyleProviderArg<IAvatarProps>): ICSSInJSStyle =>

Please, let me know what do you think

Copy link
Contributor

Choose a reason for hiding this comment

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

agreed to resolve this problem later, by means of dedicated PRs set

@kuzhelov kuzhelov added needs author feedback Author's opinion is asked and removed 🚀 ready for review labels Aug 24, 2018
@@ -1,17 +1,35 @@
import * as PropTypes from 'prop-types'
import * as React from 'react'

import { UIComponent, childrenExist, customPropTypes } from '../../lib'
import { UIComponent, childrenExist, customPropTypes, Extendable } from '../../lib'
Copy link
Member

Choose a reason for hiding this comment

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

I would expect /lib to be runtime utilities the library needs and /types to hold all our types. That would mean moving Extendable to /types as well.

There are a few more typing utilities in /types/theme.d.ts (ObjectOf, OneOrArray) that we could put in a separate /types/utils along with this Extendable util. It seems we should keep all these in one place.

Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

totally agree 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added Extendable in the utils.d.ts file in the types and updated other components accordingly. Thanks for the suggestion!

manajdov added 3 commits August 27, 2018 11:11
-updated all components with correct imports
-added typings for the AccordionTitle and AccordionContent
@mnajdova mnajdova changed the title feat(Button): add props interface feat(Props Interfaces): add props interface to Button, AccordionTitle, AccordionContent and refactoring the types definitions Aug 27, 2018
@mnajdova
Copy link
Contributor Author

As this PR turns out to solve multiple things then just define the Button prop interface, I renamed it accordiongly

@mnajdova mnajdova added 🚀 ready for review and removed needs author feedback Author's opinion is asked labels Aug 27, 2018
@mnajdova mnajdova merged commit d7b1e86 into master Aug 27, 2018
@levithomason levithomason deleted the feat/button-prop-interface branch October 29, 2019 22:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants