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

[DatePicker] reuse existing components in caption #2792

Merged
merged 21 commits into from
Aug 20, 2018
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/src/components/html-select/_html-select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Styleguide select

.#{$ns}-icon {
@extend %pt-select-arrow;
@include pt-icon-colors();
}

&.#{$ns}-minimal select {
Expand Down
19 changes: 16 additions & 3 deletions packages/core/src/components/html-select/htmlSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as React from "react";
import { DISABLED, FILL, HTML_SELECT, LARGE, MINIMAL } from "../../common/classes";
import { IOptionProps } from "../../common/props";
import { IElementRefProps } from "../html/html";
import { Icon } from "../icon/icon";
import { Icon, IIconProps } from "../icon/icon";

export interface IHTMLSelectProps
extends IElementRefProps<HTMLSelectElement>,
Expand All @@ -20,6 +20,9 @@ export interface IHTMLSelectProps
/** Whether this element should fill its container. */
fill?: boolean;

/** Props to spread to the `<Icon>` element. */
iconProps?: Partial<IIconProps>;

/** Whether to use large styles. */
large?: boolean;

Expand Down Expand Up @@ -47,7 +50,17 @@ export interface IHTMLSelectProps
/* istanbul ignore next */
export class HTMLSelect extends React.PureComponent<IHTMLSelectProps> {
public render() {
const { className, disabled, elementRef, fill, large, minimal, options = [], ...htmlProps } = this.props;
const {
className,
disabled,
elementRef,
fill,
iconProps,
large,
minimal,
options = [],
...htmlProps
} = this.props;
const classes = classNames(
HTML_SELECT,
{
Expand All @@ -70,7 +83,7 @@ export class HTMLSelect extends React.PureComponent<IHTMLSelectProps> {
{optionChildren}
{htmlProps.children}
</select>
<Icon icon="double-caret-vertical" />
<Icon icon="double-caret-vertical" {...iconProps} />
</div>
);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/datetime/src/_common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
@import "~@blueprintjs/core/src/common/variables";
@import "~@blueprintjs/icons/src/icons";

$datepicker-padding: $pt-grid-size / 2 !default;

$datepicker-min-width: $pt-grid-size * 21 !default;
$datepicker-day-size: $pt-grid-size * 3 !default;
$datepicker-header-height: $pt-grid-size * 4 !default;
Expand Down
162 changes: 50 additions & 112 deletions packages/datetime/src/_datepicker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,24 @@ $header-margin: ($header-height - $pt-input-height) / 2 !default;
line-height: 1;
}

.#{$ns}-divider {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: gonna pull this out to its own component in a separate PR, in progress now.

margin: $datepicker-padding;
background: $pt-divider-black;
width: 1px;

&.#{$ns}-vertical {
width: auto;
height: 1px;
}
}

// react-day-picker does not conform to our naming scheme
// stylelint-disable selector-class-pattern
.#{$ns}-datepicker {
position: relative;
border-radius: $pt-border-radius;
background: $datepicker-background-color;
padding: $pt-grid-size;
padding: $datepicker-padding;
user-select: none;

.DayPicker {
Expand All @@ -39,8 +50,7 @@ $header-margin: ($header-height - $pt-input-height) / 2 !default;

.DayPicker-Month {
display: inline-table;
margin: 0 auto;
padding: 0 $pt-grid-size / 2;
margin: 0 $datepicker-padding $datepicker-padding;
border-collapse: collapse;
border-spacing: 0;
user-select: none;
Expand All @@ -51,34 +61,8 @@ $header-margin: ($header-height - $pt-input-height) / 2 !default;
}
}

.DayPicker-NavBar {
position: relative;
}

.DayPicker-NavButton {
@include pt-icon-colors();
position: absolute;
top: -$datepicker-header-margin;
cursor: pointer;
padding: $datepicker-header-margin + 1;

&--prev {
left: -$datepicker-header-margin;

&::before {
@include pt-icon();
content: $pt-icon-chevron-left;
}
}

&--next {
right: -$datepicker-header-margin;

&::before {
@include pt-icon();
content: $pt-icon-chevron-right;
}
}
.DayPicker-Caption {
display: table-caption;
}

.DayPicker-Weekdays {
Expand All @@ -91,7 +75,7 @@ $header-margin: ($header-height - $pt-input-height) / 2 !default;

.DayPicker-Weekday {
@include calendar-day();
padding-top: $pt-grid-size / 2;
padding-top: $datepicker-padding;
font-weight: 600;

// normalize.css adds an underline to abbr[title] elements, remove it here
Expand Down Expand Up @@ -151,78 +135,55 @@ $header-margin: ($header-height - $pt-input-height) / 2 !default;
color: $pt-text-color-disabled;
}
}
}

.#{$ns}-datepicker-caption {
display: table-caption;
border-bottom: 1px solid $pt-divider-black;
padding: 0 $pt-grid-size;
text-align: center;

select {
margin: -$datepicker-header-margin 0 $datepicker-header-margin;
border: 0;
background: none;
cursor: pointer;
height: $pt-input-height;
// increase the size of the click target, clearing the caret on the right.
padding-right: $pt-icon-size-standard;
padding-left: $pt-grid-size / 2;
line-height: $pt-input-height;
color: $pt-text-color;
font-weight: 600;

// stylelint-disable property-no-vendor-prefix
-moz-appearance: none;
-webkit-appearance: none;
// stylelint-enable property-no-vendor-prefix

&:focus + .#{$ns}-datepicker-caption-caret {
display: inline;
}
.#{$ns}-datepicker-navbar {
display: flex;
align-items: center;
position: absolute;
top: 0;
right: 0;
left: 0;
height: $pt-button-height;

&::-ms-expand {
// IE11 styling to hide the arrow
display: none;
}
}
> :first-child {
margin-right: auto;
}
}

.#{$ns}-datepicker-caption-select {
display: inline-block;
position: relative;

&:first-child {
margin-right: $pt-grid-size;
}
.#{$ns}-datepicker-caption {
@include pt-flex-container(row, $fill: ":first-child");
justify-content: space-between;
margin-bottom: $datepicker-padding;
padding: 0 ($pt-button-height - $datepicker-padding);

// HTMLSelect overrides for a narrower appearance
select {
flex-shrink: 1;
padding-right: $pt-icon-size-standard;
padding-left: $datepicker-padding;
font-weight: 600;

&:hover .#{$ns}-datepicker-caption-caret {
fill: $pt-icon-color-hover;
+ .#{$ns}-icon {
right: 2px;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: should this be a multiple of $pt-grid-size?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in this case i think not. i really dislike using non-2 multiples of grid size because they're not reliable integers.

}
}

.#{$ns}-datepicker-caption-caret {
position: absolute;
top: 2px;
right: 0;
fill: $pt-icon-color;
pointer-events: none;
}

.#{$ns}-datepicker-footer {
display: flex;
justify-content: space-between;
margin-top: $pt-grid-size;
margin-bottom: -$pt-grid-size / 2;
border-top: 1px solid $pt-divider-black;
padding-top: $pt-grid-size / 2;
+ .#{$ns}-divider {
margin: 0;
}
}

.#{$ns}-datepicker-caption-measure {
padding-left: $pt-grid-size / 2;
padding-left: $datepicker-padding;
font-weight: 600;
}

.#{$ns}-datepicker-footer {
display: flex;
justify-content: space-between;
}

.#{$ns}-dark .#{$ns}-datepicker {
background: $dark-datepicker-background-color;

Expand Down Expand Up @@ -259,29 +220,6 @@ $header-margin: ($header-height - $pt-input-height) / 2 !default;
}
}

.#{$ns}-datepicker-caption {
border-bottom-color: $pt-dark-divider-black;

select {
color: $pt-dark-text-color;
}

option {
background-color: $dark-popover-background-color;
}

// we really need more than 4 compound selector
// to target the particular structure of this markup
// stylelint-disable-next-line
.#{$ns}-datepicker-caption-select:hover .#{$ns}-datepicker-caption-caret {
fill: $pt-dark-icon-color-hover;
}

.#{$ns}-datepicker-caption-caret {
fill: $pt-dark-icon-color;
}
}

.#{$ns}-datepicker-footer {
border-top-color: $pt-dark-divider-black;
}
Expand Down
20 changes: 6 additions & 14 deletions packages/datetime/src/_daterangepicker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
display: flex;
white-space: nowrap;

.DayPicker:not(:last-child) {
margin-right: $pt-grid-size;
// indent first navbar a bit
.DayPicker:first-of-type .#{$ns}-datepicker-navbar {
left: $datepicker-padding;
}

.DayPicker-NavButton--interactionDisabled {
Expand All @@ -20,7 +21,7 @@
.#{$ns}-daterangepicker-shortcuts + .DayPicker {
border-left: 1px solid $pt-divider-black;
min-width: $datepicker-min-width + $pt-grid-size;
padding-left: $pt-grid-size;
padding-left: $datepicker-padding;
}

// ensure min-widths are set correctly for variants of contiguous months, single month, and shortcuts
Expand All @@ -32,10 +33,6 @@
.#{$ns}-daterangepicker-shortcuts + .DayPicker {
min-width: ($datepicker-min-width + $pt-grid-size) * 2;
}

.DayPicker-Month:not(:last-child) {
margin-right: $pt-grid-size;
}
}

&.#{$ns}-daterangepicker-single-month {
Expand Down Expand Up @@ -122,11 +119,6 @@
}

.#{$ns}-menu.#{$ns}-daterangepicker-shortcuts {
display: inline-block;
margin-top: -$pt-grid-size / 2;
margin-left: -$pt-grid-size / 2;
min-width: $pt-grid-size * 15;
padding-top: 0;
padding-right: $pt-grid-size / 2;
padding-left: 0;
min-width: $pt-grid-size * 12;
padding: 0;
}
1 change: 1 addition & 0 deletions packages/datetime/src/common/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const DATEPICKER_DAY_SELECTED = `${DATEPICKER_DAY}--selected`;
export const DATEPICKER_FOOTER = `${DATEPICKER}-footer`;
export const DATEPICKER_MONTH_SELECT = `${DATEPICKER}-month-select`;
export const DATEPICKER_YEAR_SELECT = `${DATEPICKER}-year-select`;
export const DATEPICKER_NAVBAR = `${DATEPICKER}-navbar`;

export const DATERANGEPICKER = `${NS}-daterangepicker`;
export const DATERANGEPICKER_CONTIGUOUS = `${DATERANGEPICKER}-contiguous`;
Expand Down
Loading