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

feat: add Attachment component #220

Merged
merged 19 commits into from
Sep 24, 2018
Merged

feat: add Attachment component #220

merged 19 commits into from
Sep 24, 2018

Conversation

levithomason
Copy link
Member

@levithomason levithomason commented Sep 13, 2018

Attachment

An Attachment displays a file attachment.

TODO

  • Conformance test
  • Minimal doc site example
  • Teams Light theme
  • Confirm RTL usage
  • W3 accessibility check
  • Stardust accessibility check
  • Update the CHANGELOG.md
  • Handle focus style outline
  • add colors for various file types

API Proposal

This PR is implementing the Attachment component from stardust-ui/specifications#1. The latest Teams theme redlines were used. Sizes, spacing, colors, and states are redline correct for this version of the component.

image

<Attachment
  icon="file word outline"    // font awesome, for now
  header="Document.docx"  // Text shorthand
  description="800 Kb"     // Text shorthand
  action={{ icon: 'x' }}      // Button shorthand
  progress={33}               // percent complete
/>

The markup includes a div for each slot. This makes flexbox and css grid layouts easier.

<div class="ui-attachment">
  <!-- Icon -->
  <div class="...">
    <span class="ui-icon" aria-hidden="true"></span>
  </div>

  <!-- Header / Description -->
  <div class="...">
    <div class="...">Document.docx</div>
    <div class="...">800 Kb</div>
  </div>

  <!-- Action -->
  <div class="...">
    <button class="ui-button" aria-disabled="false">
        <span class="ui-icon" aria-hidden="true"></span>
    </button>
  </div>

  <!-- Progress -->
  <div class="..."></div>
</div>

Actionable

This prop styles the component to appear actionable by the user. A pointer cursor is used and a hover color is applied.

<Attachment actionable ... />

Things to know

  • Limited features: This PR only introduces the base component and its slots. Other PRs will handle the various types and colors of Attachments.
  • Icon: These are currently font awesome icons, pending feat(icons): add support for styling SVG icons #183 and subsequent work.
  • Action: The action (Button) likely needs more specific positioning and styling to match the Teams theme. This will require some button updates and maybe some theme updates. A separate PR should handle this.
  • Multiple Actions - The spec called for multiple actions, however, this usage was limited to Slack. Gmail, Teams, and Outlook all use a single action. A single action slot was used instead. The render prop callback can be used to provide a button group if the user wishes.

@levithomason levithomason force-pushed the feat/attachment branch 2 times, most recently from 06d915c to f92ef7c Compare September 14, 2018 04:08
@levithomason levithomason changed the title [WIP] feat: add Attachment component feat: add Attachment component Sep 14, 2018
@levithomason levithomason force-pushed the feat/attachment branch 3 times, most recently from 8adbc0a to fab102f Compare September 14, 2018 04:38
@levithomason levithomason force-pushed the feat/attachment branch 2 times, most recently from a4cb6b6 to dcac475 Compare September 14, 2018 04:57
}),

description: ({ props, variables }: StyleParam): ICSSInJSStyle => ({
opacity: 0.5,
Copy link
Member

Choose a reason for hiding this comment

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

Can you remove this? We don't want opacity set for the description...

}),

progress: ({ props, variables }: StyleParam): ICSSInJSStyle => ({
transition: 'width 0.2s',
Copy link
Member

Choose a reason for hiding this comment

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

looks like the animation's working!


icon: ({ props, variables }: StyleParam): ICSSInJSStyle => ({
flex: '0 0 auto',
marginRight: variables.iconSpace,
Copy link
Member

Choose a reason for hiding this comment

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

I think we don't want this margin since the attachment's 8px padding is enough to get this icon in the correct place.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is between the icon and the header/description. I believe the redline called for a larger value here.

fitted: true,
},
})}
</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering if this is the best approach, adding div's for handling our styling. I don't see a way how can the user alter these, unless using CSS selectors. I had similar propose #199 (comment) but I don't think thins should be the general approach when defining shorthands (see the comments below). What are your thoughts on this @levithomason ?

Copy link
Contributor

Choose a reason for hiding this comment

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

@mnajdova, sorry, but just to be sure - does your comment above, essentially, attribute to the problem of customizing slot's tree (the one that referenced issue is about)?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, exactly. Not strictly for this component, but just as e reference to the RFC about the customizing of the slot's tree.

import ComponentExample from 'docs/src/components/ComponentDoc/ComponentExample'
import ExampleSection from 'docs/src/components/ComponentDoc/ExampleSection'

const Slots = () => (
Copy link
Contributor

Choose a reason for hiding this comment

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

one thing that am thinking about - probably, it would be nice it we would come up with some general logic of presenting these slots in a way that those will be more visible to the client

examplePath="components/Attachment/Slots/AttachmentIconExample"
/>
<ComponentExample
title="Header"
Copy link
Contributor

@kuzhelov kuzhelov Sep 17, 2018

Choose a reason for hiding this comment

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

header is advertised as slot, and maybe I've made a false conclusion from it, but the first thing I've tried was the following - essentially, one of those things that we might expect from the shorthands:

<Attachment header={{ content: '...', styles: { color: 'red' } }} />

Apparently, it doesn't work. So, the question is the following: do we see this general pattern (that is applicable for shorthands) to be applicable to any slot content? Actually, more interested about our vision on that.

To me it seems to be a very good thing to ensure this consistency in our customization mechanisms - especially given that the following approach for style tweaking seems to be deprecated:

<Attachment styles={{ header: {..<header styles>..} }}

Copy link
Collaborator

Choose a reason for hiding this comment

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

@kuzhelov will this PR solve that? #238

Copy link
Contributor

Choose a reason for hiding this comment

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

@brianespinosa, sorry for the late response, my bad :( my promise to be better next time.

@kuzhelov will this PR solve that? #238

Unfortunately, now - and the reason is that header is currently introduced as a simple string, and not a Stardust component that encapsulates this knowledge on how this styling should be applied.

However, this is quite easy to fix - we could use Text component for header and content, so that all functionality of slots (where main aspect is styling) will be preserved.

<ExampleSection title="Variations">
<ComponentExample
title="Actionable"
description="An Attachment can be styled to indicate possible user interaction."
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure, but maybe we could better advertise to the user that this (and couple of other ones) example is clickable - frankly, was able to infer this fact only by looking on the code :)

@codecov
Copy link

codecov bot commented Sep 19, 2018

Codecov Report

Merging #220 into master will increase coverage by 0.16%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #220      +/-   ##
==========================================
+ Coverage   92.19%   92.36%   +0.16%     
==========================================
  Files          61       63       +2     
  Lines        1127     1152      +25     
  Branches      147      173      +26     
==========================================
+ Hits         1039     1064      +25     
  Misses         84       84              
  Partials        4        4
Impacted Files Coverage Δ
src/components/Attachment/index.ts 100% <100%> (ø)
src/components/Attachment/Attachment.tsx 100% <100%> (ø)
src/index.ts 100% <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 09998f8...c91e5ce. Read the comment docs.

@kuzhelov
Copy link
Contributor

kuzhelov commented Sep 19, 2018

lets address pending comments that were left for already provided functionality, and merge this PR afterwards.

After that there will be additional PR to solve the rest two requirements:

  • Handle focus style outline
  • add colors for various file types

Will take care of that.

{(header || description) && (
<div className={classes.content}>
{Text.create(header, {
defaultProps: {
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

@kuzhelov kuzhelov merged commit 5d842a0 into master Sep 24, 2018
@levithomason levithomason deleted the feat/attachment branch September 25, 2018 19:22
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

6 participants