Skip to content

Conversation

elileto
Copy link
Contributor

@elileto elileto commented Jan 21, 2019

WHY are these changes introduced?

Resolves #742

The DropZone determines its size (height and width) based on width only. This makes certain valid use cases, where the default DropZone height isn't appropriate, impossible.

WHAT is this pull request doing?

This pull request allows the consumer to set a fixed height on a wrapping parent element so that the DropZone takes its parent's height if one is provided.

Current Behaviour: (wrapped with a div given a height of 50px)
image

New Behaviour: (wrapped with a div given a height of 50px)
image

Fixed small Height small Width:
image
Fixed Medium Height Medium Width:
image
Fixed Large Height Large Width:
image
Fixed ExtraLarge Height ExtraLarge Width:
image
Fixed Small Width ExtraLarge Height
image
Fixed ExtraLarge Width Small Height
image

(Note: there are in between size variations (ie. small width, medium height etc.) The FileUpload will always render the smaller measurement of width or height.

Default Width and Heights:
image

Fixed Small Height No fixed width:
https://screenshot.click/06-26-s6fm2-7p2qn.jpg

Fixed Medium Height No fixed Width:
image

Fixed Large Height no Fixed width:
image

Fixed Extra Large Height no Fixed Width:
image

How to 🎩

🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines

Code Example with small width, small height
import * as React from 'react';
import {Page, DropZone, Stack, Thumbnail, Caption} from '../src';

interface State {
  files: object;
}

export default class Playground extends React.Component<{}, State> {
  state = {
    files: [],
  };

  render() {
    const {files} = this.state;
    const validImageTypes = ['image/gif', 'image/jpeg', 'image/png'];

    const fileUpload = !files.length && <DropZone.FileUpload />;
    const uploadedFiles = files.length > 0 && (
      <Stack vertical>
        {files.map((file, index) => (
          <Stack alignment="center" key={index}>
            <Thumbnail
              size="small"
              alt={file.name}
              source={
                validImageTypes.indexOf(file.type) > 0
                  ? window.URL.createObjectURL(file)
                  : 'https://cdn.shopify.com/s/files/1/0757/9955/files/New_Post.png?12678548500147524304'
              }
            />
            <div>
              {file.name} <Caption>{file.size} bytes</Caption>
            </div>
          </Stack>
        ))}
      </Stack>
    );

    return (
      <Page title="Playground">
        <div style={{width: 50, height: 50}}>
          <DropZone
            onDrop={(files, acceptedFiles, rejectedFiles) => {
              this.setState({
                files: [...this.state.files, ...acceptedFiles],
              });
            }}
          >
            {uploadedFiles}
            {fileUpload}
          </DropZone>
        </div>
      </Page>
    );
  }
}

medium width medium height :
import * as React from 'react';
import {Page, DropZone, Stack, Thumbnail, Caption} from '../src';

interface State {
  files: object;
}

export default class Playground extends React.Component<{}, State> {
  state = {
    files: [],
  };

  render() {
    const {files} = this.state;
    const validImageTypes = ['image/gif', 'image/jpeg', 'image/png'];

    const fileUpload = !files.length && <DropZone.FileUpload />;
    const uploadedFiles = files.length > 0 && (
      <Stack vertical>
        {files.map((file, index) => (
          <Stack alignment="center" key={index}>
            <Thumbnail
              size="small"
              alt={file.name}
              source={
                validImageTypes.indexOf(file.type) > 0
                  ? window.URL.createObjectURL(file)
                  : 'https://cdn.shopify.com/s/files/1/0757/9955/files/New_Post.png?12678548500147524304'
              }
            />
            <div>
              {file.name} <Caption>{file.size} bytes</Caption>
            </div>
          </Stack>
        ))}
      </Stack>
    );

    return (
      <Page title="Playground">
        <div style={{width: 150, height: 150}}>
          <DropZone
            onDrop={(files, acceptedFiles, rejectedFiles) => {
              this.setState({
                files: [...this.state.files, ...acceptedFiles],
              });
            }}
          >
            {uploadedFiles}
            {fileUpload}
          </DropZone>
        </div>
      </Page>
    );
  }
}
Large width, large height
import * as React from 'react';
import {Page, DropZone, Stack, Thumbnail, Caption} from '../src';

interface State {
  files: object;
}

export default class Playground extends React.Component<{}, State> {
  state = {
    files: [],
  };

  render() {
    const {files} = this.state;
    const validImageTypes = ['image/gif', 'image/jpeg', 'image/png'];

    const fileUpload = !files.length && <DropZone.FileUpload />;
    const uploadedFiles = files.length > 0 && (
      <Stack vertical>
        {files.map((file, index) => (
          <Stack alignment="center" key={index}>
            <Thumbnail
              size="small"
              alt={file.name}
              source={
                validImageTypes.indexOf(file.type) > 0
                  ? window.URL.createObjectURL(file)
                  : 'https://cdn.shopify.com/s/files/1/0757/9955/files/New_Post.png?12678548500147524304'
              }
            />
            <div>
              {file.name} <Caption>{file.size} bytes</Caption>
            </div>
          </Stack>
        ))}
      </Stack>
    );

    return (
      <Page title="Playground">
        <div style={{width: 250, height: 250}}>
          <DropZone
            onDrop={(files, acceptedFiles, rejectedFiles) => {
              this.setState({
                files: [...this.state.files, ...acceptedFiles],
              });
            }}
          >
            {uploadedFiles}
            {fileUpload}
          </DropZone>
        </div>
      </Page>
    );
  }
}
ExtraLarge width ExtraLarge height
import * as React from 'react';
import {Page, DropZone, Stack, Thumbnail, Caption} from '../src';

interface State {
  files: object;
}

export default class Playground extends React.Component<{}, State> {
  state = {
    files: [],
  };

  render() {
    const {files} = this.state;
    const validImageTypes = ['image/gif', 'image/jpeg', 'image/png'];

    const fileUpload = !files.length && <DropZone.FileUpload />;
    const uploadedFiles = files.length > 0 && (
      <Stack vertical>
        {files.map((file, index) => (
          <Stack alignment="center" key={index}>
            <Thumbnail
              size="small"
              alt={file.name}
              source={
                validImageTypes.indexOf(file.type) > 0
                  ? window.URL.createObjectURL(file)
                  : 'https://cdn.shopify.com/s/files/1/0757/9955/files/New_Post.png?12678548500147524304'
              }
            />
            <div>
              {file.name} <Caption>{file.size} bytes</Caption>
            </div>
          </Stack>
        ))}
      </Stack>
    );

    return (
      <Page title="Playground">
        <div style={{width: 500, height: 500}}>
          <DropZone
            onDrop={(files, acceptedFiles, rejectedFiles) => {
              this.setState({
                files: [...this.state.files, ...acceptedFiles],
              });
            }}
          >
            {uploadedFiles}
            {fileUpload}
          </DropZone>
        </div>
      </Page>
    );
  }
}
Default width and height
import * as React from 'react';
import {Page, DropZone, Stack, Thumbnail, Caption} from '../src';

interface State {
  files: object;
}

export default class Playground extends React.Component<{}, State> {
  state = {
    files: [],
  };

  render() {
    const {files} = this.state;
    const validImageTypes = ['image/gif', 'image/jpeg', 'image/png'];

    const fileUpload = !files.length && <DropZone.FileUpload />;
    const uploadedFiles = files.length > 0 && (
      <Stack vertical>
        {files.map((file, index) => (
          <Stack alignment="center" key={index}>
            <Thumbnail
              size="small"
              alt={file.name}
              source={
                validImageTypes.indexOf(file.type) > 0
                  ? window.URL.createObjectURL(file)
                  : 'https://cdn.shopify.com/s/files/1/0757/9955/files/New_Post.png?12678548500147524304'
              }
            />
            <div>
              {file.name} <Caption>{file.size} bytes</Caption>
            </div>
          </Stack>
        ))}
      </Stack>
    );

    return (
      <Page title="Playground">
        <DropZone
          onDrop={(files, acceptedFiles, rejectedFiles) => {
            this.setState({
              files: [...this.state.files, ...acceptedFiles],
            });
          }}
        >
          {uploadedFiles}
          {fileUpload}
        </DropZone>
      </Page>
    );
  }
}
Small width, Large Height
import * as React from 'react';
import {Page, DropZone, Stack, Thumbnail, Caption} from '../src';

interface State {
  files: object;
}

export default class Playground extends React.Component<{}, State> {
  state = {
    files: [],
  };

  render() {
    const {files} = this.state;
    const validImageTypes = ['image/gif', 'image/jpeg', 'image/png'];

    const fileUpload = !files.length && <DropZone.FileUpload />;
    const uploadedFiles = files.length > 0 && (
      <Stack vertical>
        {files.map((file, index) => (
          <Stack alignment="center" key={index}>
            <Thumbnail
              size="small"
              alt={file.name}
              source={
                validImageTypes.indexOf(file.type) > 0
                  ? window.URL.createObjectURL(file)
                  : 'https://cdn.shopify.com/s/files/1/0757/9955/files/New_Post.png?12678548500147524304'
              }
            />
            <div>
              {file.name} <Caption>{file.size} bytes</Caption>
            </div>
          </Stack>
        ))}
      </Stack>
    );

    return (
      <Page title="Playground">
        <div style={{width: 50, height: 500}}>
          <DropZone
            onDrop={(files, acceptedFiles, rejectedFiles) => {
              this.setState({
                files: [...this.state.files, ...acceptedFiles],
              });
            }}
          >
            {uploadedFiles}
            {fileUpload}
          </DropZone>
        </div>
      </Page>
    );
  }
}
Large Width Small Height
import * as React from 'react';
import {Page, DropZone, Stack, Thumbnail, Caption} from '../src';

interface State {
  files: object;
}

export default class Playground extends React.Component<{}, State> {
  state = {
    files: [],
  };

  render() {
    const {files} = this.state;
    const validImageTypes = ['image/gif', 'image/jpeg', 'image/png'];

    const fileUpload = !files.length && <DropZone.FileUpload />;
    const uploadedFiles = files.length > 0 && (
      <Stack vertical>
        {files.map((file, index) => (
          <Stack alignment="center" key={index}>
            <Thumbnail
              size="small"
              alt={file.name}
              source={
                validImageTypes.indexOf(file.type) > 0
                  ? window.URL.createObjectURL(file)
                  : 'https://cdn.shopify.com/s/files/1/0757/9955/files/New_Post.png?12678548500147524304'
              }
            />
            <div>
              {file.name} <Caption>{file.size} bytes</Caption>
            </div>
          </Stack>
        ))}
      </Stack>
    );

    return (
      <Page title="Playground">
        <div style={{width: 500, height: 50}}>
          <DropZone
            onDrop={(files, acceptedFiles, rejectedFiles) => {
              this.setState({
                files: [...this.state.files, ...acceptedFiles],
              });
            }}
          >
            {uploadedFiles}
            {fileUpload}
          </DropZone>
        </div>
      </Page>
    );
  }
}

🎩 checklist

@elileto elileto self-assigned this Jan 21, 2019
@BPScott BPScott temporarily deployed to polaris-react-pr-908 January 21, 2019 16:24 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-908 January 21, 2019 17:54 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-908 January 21, 2019 18:00 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-908 January 21, 2019 19:00 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-908 January 21, 2019 20:04 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-908 January 21, 2019 21:36 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-908 January 21, 2019 21:39 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-908 January 23, 2019 19:50 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-908 January 23, 2019 20:08 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-908 January 23, 2019 20:42 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-908 January 23, 2019 20:43 Inactive
@elileto elileto changed the title [WIP][DropZone] Constrain drop zone height based on inherited wrapper height [DropZone] Constrain drop zone height based on inherited wrapper height Jan 23, 2019
@elileto elileto removed the request for review from solonaarmstrong-zz January 25, 2019 16:07
@elileto elileto changed the title [DropZone] Constrain drop zone height based on inherited wrapper height [WIP][DropZone] Constrain drop zone height based on inherited wrapper height Jan 25, 2019
@BPScott BPScott temporarily deployed to polaris-react-pr-908 January 25, 2019 21:32 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-908 January 25, 2019 21:51 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-908 January 25, 2019 22:05 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-908 January 25, 2019 22:09 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-908 February 15, 2019 15:01 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-908 February 18, 2019 17:11 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-908 February 18, 2019 18:59 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-908 February 18, 2019 19:00 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-908 February 19, 2019 22:32 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-908 February 19, 2019 22:40 Inactive
Copy link
Member

@AndrewMusgrave AndrewMusgrave left a comment

Choose a reason for hiding this comment

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

🎉

@BPScott BPScott temporarily deployed to polaris-react-pr-908 February 20, 2019 17:42 Inactive
@elileto elileto merged commit 61aca8f into master Feb 20, 2019
@elileto elileto deleted the dropzone-height branch February 20, 2019 22:13
@AndrewMusgrave AndrewMusgrave restored the dropzone-height branch March 6, 2019 20:05
@kaelig kaelig deleted the dropzone-height branch June 27, 2019 01:08
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.

DropZone height is not respected

5 participants