Skip to content

Commit

Permalink
Merge pull request #237 from dabapps/fix-safari-collapse-fade-bug
Browse files Browse the repository at this point in the history
Fix safari collapse fade bug
  • Loading branch information
lCharlie123l authored Apr 4, 2018
2 parents 4337578 + f0bda44 commit f52683e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dabapps/roe",
"version": "0.9.5",
"version": "0.9.6",
"description": "A Collection of React Components for Project Development",
"main": "dist/js/index.js",
"types": "dist/js/index.d.ts",
Expand Down
13 changes: 10 additions & 3 deletions src/ts/components/collapse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const ENOUGH_TIME_FOR_RERENDER = 50;
const DEFAULT_HEIGHT = 0;
const DEFAULT_DURATION = 200;
const DEFAULT_FADE_HEIGHT = 50;
const DEFAULT_FADE_COLOR = '#FFF';
const DEFAULT_TRANSPARENT_COLOR = 'rgba(255, 255, 255, 0)';
const DEFAULT_FADE_COLOR = 'rgba(255, 255, 255, 1)';

export interface CollapseProps
extends ComponentProps,
Expand All @@ -34,9 +35,14 @@ export interface CollapseProps
fadeOut?: boolean;
/**
* Color to fade to
* @default white
* @default rgba(255, 255, 255, 1)
*/
fadeColor?: string;
/**
* Transparent color to fade from (this should be a transparent version of the fadeColor)
* @default rgba(255, 255, 255, 0)
*/
transparentColor?: string;
/**
* Height of the faded area
* @default 50
Expand Down Expand Up @@ -125,6 +131,7 @@ export class Collapse extends PureComponent<CollapseProps, CollapseState> {
fadeOut,
fadeColor = DEFAULT_FADE_COLOR,
fadeHeight = DEFAULT_FADE_HEIGHT,
transparentColor = DEFAULT_TRANSPARENT_COLOR,
open,
maxCollapsedHeight,
animationDuration = DEFAULT_DURATION,
Expand All @@ -147,7 +154,7 @@ export class Collapse extends PureComponent<CollapseProps, CollapseState> {
position: 'absolute' as 'absolute',
bottom: 0,
opacity: opening ? 0 : 1,
background: `linear-gradient(transparent, ${fadeColor} 80%)`,
background: `linear-gradient(${transparentColor}, ${fadeColor} 80%)`,
transition: `ease-in-out ${animationDuration}ms opacity`,
};

Expand Down
28 changes: 14 additions & 14 deletions tests/__snapshots__/collapse.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ exports[`Collapse should close to custom height 2`] = `
className="collapse-fade"
style={
Object {
"background": "linear-gradient(transparent, #FFF 80%)",
"background": "linear-gradient(rgba(255, 255, 255, 0), rgba(255, 255, 255, 1) 80%)",
"bottom": 0,
"height": 50,
"opacity": 0,
Expand Down Expand Up @@ -133,7 +133,7 @@ exports[`Collapse should close to custom height 3`] = `
className="collapse-fade"
style={
Object {
"background": "linear-gradient(transparent, #FFF 80%)",
"background": "linear-gradient(rgba(255, 255, 255, 0), rgba(255, 255, 255, 1) 80%)",
"bottom": 0,
"height": 50,
"opacity": 1,
Expand Down Expand Up @@ -168,7 +168,7 @@ exports[`Collapse should close to custom height 4`] = `
className="collapse-fade"
style={
Object {
"background": "linear-gradient(transparent, #FFF 80%)",
"background": "linear-gradient(rgba(255, 255, 255, 0), rgba(255, 255, 255, 1) 80%)",
"bottom": 0,
"height": 50,
"opacity": 1,
Expand Down Expand Up @@ -221,7 +221,7 @@ exports[`Collapse should close to default height 2`] = `
className="collapse-fade"
style={
Object {
"background": "linear-gradient(transparent, #FFF 80%)",
"background": "linear-gradient(rgba(255, 255, 255, 0), rgba(255, 255, 255, 1) 80%)",
"bottom": 0,
"height": 50,
"opacity": 0,
Expand Down Expand Up @@ -255,7 +255,7 @@ exports[`Collapse should close to default height 3`] = `
className="collapse-fade"
style={
Object {
"background": "linear-gradient(transparent, #FFF 80%)",
"background": "linear-gradient(rgba(255, 255, 255, 0), rgba(255, 255, 255, 1) 80%)",
"bottom": 0,
"height": 50,
"opacity": 1,
Expand Down Expand Up @@ -289,7 +289,7 @@ exports[`Collapse should close to default height 4`] = `
className="collapse-fade"
style={
Object {
"background": "linear-gradient(transparent, #FFF 80%)",
"background": "linear-gradient(rgba(255, 255, 255, 0), rgba(255, 255, 255, 1) 80%)",
"bottom": 0,
"height": 50,
"opacity": 1,
Expand Down Expand Up @@ -361,7 +361,7 @@ exports[`Collapse should match snapshot with customized fade out 1`] = `
className="collapse-fade"
style={
Object {
"background": "linear-gradient(transparent, red 80%)",
"background": "linear-gradient(rgba(0, 0, 0, 0), red 80%)",
"bottom": 0,
"height": 10,
"opacity": 1,
Expand Down Expand Up @@ -390,7 +390,7 @@ exports[`Collapse should match snapshot with fade out 1`] = `
className="collapse-fade"
style={
Object {
"background": "linear-gradient(transparent, #FFF 80%)",
"background": "linear-gradient(rgba(255, 255, 255, 0), rgba(255, 255, 255, 1) 80%)",
"bottom": 0,
"height": 50,
"opacity": 1,
Expand Down Expand Up @@ -424,7 +424,7 @@ exports[`Collapse should open from custom height 1`] = `
className="collapse-fade"
style={
Object {
"background": "linear-gradient(transparent, #FFF 80%)",
"background": "linear-gradient(rgba(255, 255, 255, 0), rgba(255, 255, 255, 1) 80%)",
"bottom": 0,
"height": 50,
"opacity": 1,
Expand Down Expand Up @@ -459,7 +459,7 @@ exports[`Collapse should open from custom height 2`] = `
className="collapse-fade"
style={
Object {
"background": "linear-gradient(transparent, #FFF 80%)",
"background": "linear-gradient(rgba(255, 255, 255, 0), rgba(255, 255, 255, 1) 80%)",
"bottom": 0,
"height": 50,
"opacity": 1,
Expand Down Expand Up @@ -494,7 +494,7 @@ exports[`Collapse should open from custom height 3`] = `
className="collapse-fade"
style={
Object {
"background": "linear-gradient(transparent, #FFF 80%)",
"background": "linear-gradient(rgba(255, 255, 255, 0), rgba(255, 255, 255, 1) 80%)",
"bottom": 0,
"height": 50,
"opacity": 0,
Expand Down Expand Up @@ -548,7 +548,7 @@ exports[`Collapse should open from default height 1`] = `
className="collapse-fade"
style={
Object {
"background": "linear-gradient(transparent, #FFF 80%)",
"background": "linear-gradient(rgba(255, 255, 255, 0), rgba(255, 255, 255, 1) 80%)",
"bottom": 0,
"height": 50,
"opacity": 1,
Expand Down Expand Up @@ -582,7 +582,7 @@ exports[`Collapse should open from default height 2`] = `
className="collapse-fade"
style={
Object {
"background": "linear-gradient(transparent, #FFF 80%)",
"background": "linear-gradient(rgba(255, 255, 255, 0), rgba(255, 255, 255, 1) 80%)",
"bottom": 0,
"height": 50,
"opacity": 1,
Expand Down Expand Up @@ -616,7 +616,7 @@ exports[`Collapse should open from default height 3`] = `
className="collapse-fade"
style={
Object {
"background": "linear-gradient(transparent, #FFF 80%)",
"background": "linear-gradient(rgba(255, 255, 255, 0), rgba(255, 255, 255, 1) 80%)",
"bottom": 0,
"height": 50,
"opacity": 0,
Expand Down
8 changes: 7 additions & 1 deletion tests/collapse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ describe('Collapse', () => {

it('should match snapshot with customized fade out', () => {
const tree = renderer.create(
<Collapse open={false} fadeOut fadeColor="red" fadeHeight={10} />
<Collapse
open={false}
fadeOut
fadeColor="red"
fadeHeight={10}
transparentColor="rgba(0, 0, 0, 0)"
/>
);

expect(tree).toMatchSnapshot();
Expand Down

0 comments on commit f52683e

Please sign in to comment.