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

DropZone - File upload positioning issue #1127

Closed
wants to merge 1 commit into from
Closed

Conversation

dleroux
Copy link
Contributor

@dleroux dleroux commented Mar 6, 2019

WHY are these changes introduced?

In 3.9 this PR added the ability to specify a height to the drop zone.

When a height container does have a height, we added display: flex to ensure that the DropZone.FileUpload was vertically and horizontally aligned. This however causes issue because we really have no control what the children of that container will be (In web this breaks the ProductShow implementation)

WHAT is this pull request doing?

From the DropZone component we also don't know what the children are. It could be 'DropZone.FileUpload` or not. So the best solution I could come up with, is the add a Flex layout to the FileUpload if it's the only child. I really don't like the fact the FileUpload is responsible for it's positioning, but it's the safest approach I could think of.

**This PR is not ready to deploy. It's here for discussion. Also note I branched right from 3.9 in case we end up doing a patch release for this **

How to 🎩

🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines

Copy-paste this code in playground/Playground.tsx:
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>
    );
  }
}

🎩 checklist

@BPScott BPScott temporarily deployed to polaris-react-pr-1127 March 6, 2019 13:35 Inactive
@dleroux
Copy link
Contributor Author

dleroux commented Mar 6, 2019

I see Percy spotted an issue with the "Nested Drop Zone" example.

@dleroux
Copy link
Contributor Author

dleroux commented Mar 6, 2019

Another option discussed on slack would be to add a prop to <DropZone.FileUpload centered={false} /> set to true by default.

@BPScott BPScott temporarily deployed to polaris-react-pr-1127 March 6, 2019 14:56 Inactive
@AndrewMusgrave
Copy link
Member

At a glance feels odd to me to have non-structure components have props that affect positioning. Curious what everyone else thinks about this?

@dleroux
Copy link
Contributor Author

dleroux commented Mar 6, 2019

An option would be to leave it as is, and have the consumer override the display: flex with their own container if they need to.

@BPScott BPScott temporarily deployed to polaris-react-pr-1127 March 6, 2019 16:01 Inactive
@BPScott BPScott temporarily deployed to polaris-react-pr-1127 March 6, 2019 16:03 Inactive
@danrosenthal
Copy link
Contributor

I've pushed a fix that adds a centerAlignChildren prop that defaults to true. This breaks our component model in ways, as its not typically desirable to have parents lay out their children. It's also not great to have props that default to true. In this case, since this will technically avoid a breaking change, I think it's okay.

I don't have much more time to focus on this, so if @elizabethletourneau with the support of @AndrewMusgrave could finish this off, that would be appreciated.

screenshots
screen shot 2019-03-06 at 9 56 46 am
screen shot 2019-03-06 at 9 56 53 am
<React.Fragment>
  <div style={{width: 50}}>
    <DropZone>
      <DropZone.FileUpload />
    </DropZone>
  </div>
  <div style={{width: 114}}>
    <DropZone>
      <DropZone.FileUpload />
    </DropZone>
  </div>
  <div style={{width: 50}}>
    <DropZone centerAlignChildren={false}>
      <DropZone.FileUpload />
    </DropZone>
  </div>
  <div style={{width: 114}}>
    <DropZone centerAlignChildren={false}>
      <DropZone.FileUpload />
    </DropZone>
  </div>
  <div style={{width: 500}}>
    <DropZone centerAlignChildren={false}>
      <DropZone.FileUpload />
    </DropZone>
  </div>
  <div style={{width: 500, height: 500}}>
    <DropZone centerAlignChildren={false}>
      <DropZone.FileUpload />
    </DropZone>
  </div>
</React.Fragment>

@BPScott BPScott temporarily deployed to polaris-react-pr-1127 March 6, 2019 16:13 Inactive
@danrosenthal
Copy link
Contributor

Closing in favor of #1129

@danrosenthal danrosenthal deleted the fix-drop-zone branch March 6, 2019 18: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.

4 participants