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

feat(Carousel): base component #1979

Merged
merged 93 commits into from
Nov 19, 2019
Merged

feat(Carousel): base component #1979

merged 93 commits into from
Nov 19, 2019

Conversation

silviuaavram
Copy link
Collaborator

@silviuaavram silviuaavram commented Sep 27, 2019

Separate component for the navigation (based on the Menu implementation).

Features:

  • component class, styles, docs example.
  • aria-live with announcements.
  • navigation-bar
  • behavior with tabIndex and others.
  • transition and state management by buttons.
  • state management by left-right arrows.
  • smooth transition on click while animation is in progress. Transition time needs to be updated with what is left + new transition. (if current item transitioned half-way and another next is pressed, then transition needs to be 3/2 transition time). Should be done with timers. Second option: https://kenwheeler.github.io/slick/ cancels future transitions while a transition is performed. AKA: use throttle with timeout as the transition time.
  • variations for next and previous button placements via props.
  • variations for navigation bar via props.
  • controlled state for activeIndex. Add props.
  • unit tests.
  • hide buttons if clicking them will not move next/previous.
  • container for next and previous buttons to facilitate position variation.
  • separation between Carousel, Item and Slide.
  • options for transitions: translate, fade and display: none / display: block
  • variation for navigation bar positioning.
  • variation for fading next/previous button on mouse hover over carousel.

After API discussion:

  • have component for Navigation, paddles.
  • have content rendered in item instead of Slide.

@codecov
Copy link

codecov bot commented Sep 27, 2019

Codecov Report

Merging #1979 into master will decrease coverage by 0.14%.
The diff coverage is 3.79%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1979      +/-   ##
==========================================
- Coverage   75.83%   75.68%   -0.15%     
==========================================
  Files         160      163       +3     
  Lines        5569     5572       +3     
  Branches     1628     1620       -8     
==========================================
- Hits         4223     4217       -6     
- Misses       1332     1342      +10     
+ Partials       14       13       -1
Impacted Files Coverage Δ
packages/react/src/index.ts 100% <ø> (ø) ⬆️
...ackages/react/src/components/Carousel/Carousel.tsx 1.51% <1.51%> (ø)
...ges/react/src/components/Carousel/CarouselItem.tsx 12.5% <12.5%> (ø)
...es/react/src/components/Carousel/CarouselSlide.tsx 20% <20%> (ø)
...ckages/react/src/components/Popup/PopupContent.tsx 95.45% <0%> (-4.55%) ⬇️
...ges/react/src/components/Attachment/Attachment.tsx 87.5% <0%> (-3.81%) ⬇️
...kages/react/src/components/Toolbar/ToolbarItem.tsx 45.16% <0%> (ø) ⬆️
packages/react/src/lib/renderComponent.tsx 84.05% <0%> (ø) ⬆️
...es/react/src/components/Tooltip/TooltipContent.tsx 100% <0%> (ø) ⬆️
... and 3 more

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 d4cc17b...0977bb6. Read the comment docs.

navigation={{
'aria-label': 'people portraits',
items: carouselItems.map((item, index) => ({
key: index,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
key: index,
key: item.id,

key: index,
'aria-label': imageAltTags[item.id],
'aria-controls': item.id,
icon: { name: 'stardust-circle', size: 'smallest' as SizeValue },
Copy link
Contributor

Choose a reason for hiding this comment

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

Why aren't these default props for this icon?

* A Carousel can position its navigation to the bottom by default,
* to the top, to the left or to the right of the content.
*/
navigationPosition?: 'bottom' | 'top' | 'left' | 'right'
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
navigationPosition?: 'bottom' | 'top' | 'left' | 'right'
navigationPosition?: 'below' | 'above' | 'start' | 'end'

@mnajdova mnajdova changed the title feat: carousel component feat(Carousel): base component Nov 15, 2019
CHANGELOG.md Outdated
@@ -34,6 +34,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Add bounce animation to button clicks in Teams theme @notandrew ([#1724](https://github.com/stardust-ui/react/pull/1724))
- Update Silver color scheme, adding `foregroundHover`, `foregroundPressed` and `background` definitions @pompomon ([#2078](https://github.com/microsoft/fluent-ui-react/pull/2078))
- Expanding experimental accessibility schema to more components @mshoho ([#2052](https://github.com/stardust-ui/react/pull/2052))
- `Carousel` component @silviuavram ([#1979](https://github.com/microsoft/fluent-ui-react/pull/1979))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- `Carousel` component @silviuavram ([#1979](https://github.com/microsoft/fluent-ui-react/pull/1979))
- Add base `Carousel` component @silviuavram ([#1979](https://github.com/microsoft/fluent-ui-react/pull/1979))

import * as React from 'react'
import { Carousel, Image } from '@stardust-ui/react'

const imageAltTags = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Inline these

circular?: boolean

/** Initial activeIndex value. */
defaultActiveIndex?: number | string
Copy link
Contributor

Choose a reason for hiding this comment

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

add onActiveIndexChange method

navigationPosition?: 'bottom' | 'top' | 'left' | 'right'

/** A Carousel's paddles may fade away when mouse is not hovering the code. */
paddlesFade?: boolean
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not add this prop just now.. If we see need in the future we can add it.

* On slide transition, the Carousel may translate the slides' position,
* fade their appearance or just hide and show without any animation.
*/
slideTransition?: 'translate' | 'fade' | 'display'
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not add this at this moment, and implement in the styles whatever is necessary for the team. I don't think one application will have different slideTransition. If this turns out to be a case, we can add it later.


static defaultProps = {
accessibility: carouselBehavior,
as: 'div',
Copy link
Contributor

Choose a reason for hiding this comment

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

this is by default, no need to add it here

defaultProps: () => ({
className: Carousel.slotClassNames.paddlePrevious,
iconOnly: true,
icon: 'stardust-chevron-left',
Copy link
Contributor

Choose a reason for hiding this comment

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

let's add these in the defaultProps, instead of the empty objects.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If I do this, it will override all of them each time I add only one field. For instance in the pagination example I added aria-label as shortcuts and the default values were removed. I would consider leaving theme here.

paddlePrevious,
),
}),
overrideProps: (predefinedProps: ButtonProps) => ({
Copy link
Contributor

Choose a reason for hiding this comment

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

Extract these to functions

}

static slotClassNames: CarouselItemSlotClassNames = {
itemPositionContainer: `${CarouselItem.className}__itemPositionContainer`,
Copy link
Contributor

Choose a reason for hiding this comment

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

itemPositionText

secondary?: boolean

/** Carousel navigation items can by highlighted using underline. */
underlined?: boolean
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not add underlined for now

}

handleBlur = (e: React.SyntheticEvent) => {
this.setState({ isFromKeyboard: false })
Copy link
Contributor

Choose a reason for hiding this comment

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

Try replacing this with 'focus-visible'

@@ -33,6 +33,8 @@ const theme: ThemeInput = {
'stardust-arrow-up': processedIcons['triangle-up'],
'stardust-arrow-down': processedIcons['triangle-down'],
'stardust-arrow-end': processedIcons['triangle-right'],
'stardust-chevron-left': processedIcons['chevron-left'],
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use start and end


paddleNext.simulate('click')

expect(pagination.getDOMNode().textContent).toBe(`4 of ${items.length}`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please check this again, paddleNext should not be visible

jest.runAllTimers()
})

it('should not show pagination if prop is passed', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
it('should not show pagination if prop is passed', () => {
it('should not show pagination if navigation prop is passed', () => {

Copy link
Contributor

Choose a reason for hiding this comment

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

And add the opposite scenario test (navigation: false)

@@ -207,6 +209,8 @@ export default {
'canvas-add-page': canvasAddPage,
chat,
'chevron-down': chevronDown,
'chevron-start': chevronStart,
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 if we should export these icons. Can you please just export the stardust-* icons

@silviuaavram silviuaavram merged commit d88c977 into master Nov 19, 2019
@silviuaavram silviuaavram deleted the feat/carousel-component branch November 19, 2019 10:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
⚙️ enhancement New feature or request new component Component planned to be added to Stardust 🚀 ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants