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

Add position option for Toast #219

Merged
merged 14 commits into from
Mar 29, 2019
Merged

Conversation

zhirzh
Copy link
Member

@zhirzh zhirzh commented Mar 26, 2019

fixes #218

@zhirzh zhirzh requested a review from ritz078 March 26, 2019 11:49
src/components/Toast.tsx Outdated Show resolved Hide resolved
src/components/typings/Toast.ts Outdated Show resolved Hide resolved
},

transitions: {
from: { transform: "translateX(-10px)" },
Copy link
Contributor

@ritz078 ritz078 Mar 27, 2019

Choose a reason for hiding this comment

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

Repeating these will increase file size. Since these are strings, the change won't be negligible. We can't compromise on size for readability. So, extract these into separate objects and use them here.

Copy link
Member Author

@zhirzh zhirzh Mar 27, 2019

Choose a reason for hiding this comment

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

replacing repeating code with a dynamic function gives slightly longer code (see here)

Copy link
Contributor

Choose a reason for hiding this comment

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

That link is giving 404

Copy link
Contributor

@ritz078 ritz078 Mar 27, 2019

Choose a reason for hiding this comment

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

What I asked was different.

const centerTransfrom = {
  from: { transform: "translateX(-50%) translateY(-10px)" },
      enter: { transform: "translateX(-50%) translateY(0)" },
      leave: { transform: "translateX(-50%) translateY(-10px)" }
}

const customStyles = {
  [ToastPosition.TOP]: {
    style: {
      top: 20,
      left: "50%"
    },
  transitions: centerTransform
}}

now you can use centerTransform at two places.

Copy link
Member Author

Choose a reason for hiding this comment

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

the centerTransform object won't be usable by ToastPosition.BOTTOM because the translateY() is negative but needs to be positive

@ritz078
Copy link
Contributor

ritz078 commented Mar 27, 2019

also the tests are failing.

@zhirzh
Copy link
Member Author

zhirzh commented Mar 27, 2019

fixed tests

Toast.show("hello", "success", {
time: 1000,
position: select(
"bottom",
Copy link
Contributor

Choose a reason for hiding this comment

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

change this to position

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed in 5c997ea

@ritz078
Copy link
Contributor

ritz078 commented Mar 27, 2019

Also, It's crashing for TOP position in storybook

@azizhk
Copy link
Contributor

azizhk commented Mar 28, 2019

Run yarn build and then yarn test to see these tests fail on your local machine.

@azizhk
Copy link
Contributor

azizhk commented Mar 28, 2019

I guess tests are failing because the code generated by Typescript is not fully tree-shakeable.
microsoft/TypeScript#27604

@zhirzh
Copy link
Member Author

zhirzh commented Mar 28, 2019

exporting ToastPosition enum is the cause

var ToastPosition;
(function (ToastPosition) {
  ToastPosition[ToastPosition["BOTTOM"] = 0] = "BOTTOM";
  ToastPosition[ToastPosition["BOTTOM_LEFT"] = 1] = "BOTTOM_LEFT";
  ToastPosition[ToastPosition["BOTTOM_RIGHT"] = 2] = "BOTTOM_RIGHT";
  ToastPosition[ToastPosition["TOP"] = 3] = "TOP";
  ToastPosition[ToastPosition["TOP_LEFT"] = 4] = "TOP_LEFT";
  ToastPosition[ToastPosition["TOP_RIGHT"] = 5] = "TOP_RIGHT";
})(ToastPosition || (ToastPosition = {}));

@ritz078 ritz078 merged commit efb1489 into master Mar 29, 2019
@ritz078 ritz078 deleted the feature/toast-position-options branch March 29, 2019 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to have different positions for Toast
3 participants