Skip to content

Commit

Permalink
[PLAY-1463] Linter: Kits T - W (except Typeahead) (#3573)
Browse files Browse the repository at this point in the history
**What does this PR do?**

- ✅ Resurrect PLAY-1086 **without** Typeahead changes which caused bugs.
- ✅ Table, Text, Time, Title, Tooltip, Treemap, User, Walkthrough,
Weekday

**How to test?**
We've already tested PLAY-1086 with an alpha.

We're going to retest everything except for Typeahead. See the
[story](https://runway.powerhrg.com/backlog_items/PLAY-1463).

#### Checklist:
- [x] **LABELS** Add a label: `enhancement`, `bug`, `improvement`, `new
kit`, `deprecated`, or `breaking`. See [Changelog &
Labels](https://github.com/powerhome/playbook/wiki/Changelog-&-Labels)
for details.
- [x] **DEPLOY** I have added the `milano` label to show I'm ready for a
review.

---------

Co-authored-by: Nida Ghuman <nidaqg@gmail.com>
  • Loading branch information
kangaree and nidaqg authored Aug 13, 2024
1 parent 4d04b47 commit 3b54c73
Show file tree
Hide file tree
Showing 27 changed files with 397 additions and 370 deletions.
2 changes: 1 addition & 1 deletion playbook/app/pb_kits/playbook/pb_table/_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type TableProps = {
verticalBorder?: boolean,
} & GlobalProps

const Table = (props: TableProps) => {
const Table = (props: TableProps): React.ReactElement => {
const {
aria = {},
children,
Expand Down
8 changes: 4 additions & 4 deletions playbook/app/pb_kits/playbook/pb_table/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import PbEnhancedElement from '../pb_enhanced_element'

export default class PbTable extends PbEnhancedElement {
static get selector() {
static get selector(): string {
return '.table-responsive-collapse'
}

connect() {
connect(): void {
const tables = document.querySelectorAll('.table-responsive-collapse');

// Each Table
[].forEach.call(tables, (table: HTMLTableElement) => {
// Header Titles
let headers: string[] = [];
const headers: string[] = [];
[].forEach.call(table.querySelectorAll('th'), (header: HTMLTableCellElement) => {
let colSpan = header.colSpan
const colSpan = header.colSpan
for (let i = 0; i < colSpan; i++) {
headers.push(header.textContent.replace(/\r?\n|\r/, ''));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type TableBodyPropTypes = {
tag?: "table" | "div";
};

const TableBody = (props: TableBodyPropTypes) => {
const TableBody = (props: TableBodyPropTypes): React.ReactElement => {
const {
aria = {},
children,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type TableCellPropTypes = {
text?: string
};

const TableCell = (props: TableCellPropTypes) => {
const TableCell = (props: TableCellPropTypes): React.ReactElement => {
const {
aria = {},
children,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type TableHeadPropTypes = {
tag?: "table" | "div";
};

const TableHead = (props: TableHeadPropTypes) => {
const TableHead = (props: TableHeadPropTypes): React.ReactElement => {
const {
aria = {},
children,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type TableHeaderPropTypes = {
text?: string;
};

const TableHeader = (props: TableHeaderPropTypes) => {
const TableHeader = (props: TableHeaderPropTypes): React.ReactElement => {
const {
aria = {},
children,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type TableRowPropTypes = {
tag?: "table" | "div";
};

const TableRow = (props: TableRowPropTypes) => {
const TableRow = (props: TableRowPropTypes): React.ReactElement => {
const {
aria = {},
children,
Expand Down
2 changes: 2 additions & 0 deletions playbook/app/pb_kits/playbook/pb_table/table.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable react/no-multi-comp */

import React from "react";
import { ensureAccessible, renderKit, render, screen } from "../utilities/test-utils"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const TextInput = (props: TextInputProps, ref: React.LegacyRef<HTMLInputElement>
required={required}
type={type}
value={value}
/>)
/>)
)

const addOnInput = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import TextInput from '../../pb_text_input/_text_input'
import Title from '../../pb_title/_title'

const TextInputDefault = (props) => {
const [firstName, setFirstName] = useState('')
const handleOnChangeFirstName = ({ target }) => {
setFirstName(target.value)
}
const ref = React.createRef()

const [firstName, setFirstName] = useState('')
const [formFields, setFormFields] = useState({
firstName: 'Jane',
lastName: 'Doe',
Expand Down
72 changes: 45 additions & 27 deletions playbook/app/pb_kits/playbook/pb_textarea/_textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ const Textarea = ({
label,
maxCharacters,
name,
// eslint-disable-next-line @typescript-eslint/no-empty-function
onChange = () => {},
placeholder,
required,
rows = 4,
value,
...props
}: TextareaProps, ref: any) => {
ref = useRef<HTMLTextAreaElement>(null)
}: TextareaProps) => {
const ref = useRef<HTMLTextAreaElement>(null)
useEffect(() => {
if (ref.current && resize === 'auto') {
PbTextarea.addMatch(ref.current)
Expand All @@ -71,58 +72,75 @@ const Textarea = ({
const resizeClass = `resize_${resize}`
const classes = classnames('pb_textarea_kit', errorClass, inlineClass, resizeClass, globalProps(props), className)
const noCount = typeof characterCount !== 'undefined'
const ariaProps: {[key: string]: any} = buildAriaProps(aria)
const dataProps: {[key: string]: any} = buildDataProps(data)
const ariaProps: {[key: string]: string} = buildAriaProps(aria)
const dataProps: {[key: string]: string} = buildDataProps(data)
const htmlProps = buildHtmlProps(htmlOptions)
const characterCounter = () => {
return maxCharacters && characterCount ? `${checkIfZero(characterCount)} / ${maxCharacters}` : `${checkIfZero(characterCount)}`
}

const checkIfZero = (characterCount: string | number) => {
return characterCount == 0 ? characterCount.toString() : characterCount
}
const characterCounter = () => {
return maxCharacters && characterCount ? `${checkIfZero(characterCount)} / ${maxCharacters}` : `${checkIfZero(characterCount)}`
}

return (
<div
{...ariaProps}
{...dataProps}
{...htmlProps}
className={classes}
{...ariaProps}
{...dataProps}
{...htmlProps}
className={classes}
>
<Caption text={label} />
{children || (
<textarea
className="pb_textarea_kit"
disabled={disabled}
name={name}
onChange={onChange}
placeholder={placeholder}
ref={ref}
required={required}
rows={rows}
value={value}
{...props}
className="pb_textarea_kit"
disabled={disabled}
name={name}
onChange={onChange}
placeholder={placeholder}
ref={ref}
required={required}
rows={rows}
value={value}
{...props}
/>
)}

{error ? (
<>
{characterCount ? (
<Flex spacing="between" vertical="center">
<Flex
spacing="between"
vertical="center"
>
<FlexItem>
<Body margin="none" status="negative" text={error} />
<Body
margin="none"
status="negative"
text={error}
/>
</FlexItem>
<FlexItem>
<Caption margin="none" size="xs" text={characterCounter()} />
<Caption
margin="none"
size="xs"
text={characterCounter()}
/>
</FlexItem>
</Flex>
) : (
<Body status="negative" text={error} />
<Body
status="negative"
text={error}
/>
)}
</>
) : (
noCount && (
<Caption margin="none" size="xs" text={characterCounter()} />
<Caption
margin="none"
size="xs"
text={characterCounter()}
/>
)
)}
</div>
Expand Down
6 changes: 3 additions & 3 deletions playbook/app/pb_kits/playbook/pb_textarea/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import PbEnhancedElement from '../pb_enhanced_element'
export default class PbTextarea extends PbEnhancedElement {
style: {[key: string]: string}
scrollHeight: string
static get selector() {
static get selector(): string {
return '.resize_auto textarea'
}

onInput() {
onInput(): void {
this.style.height = 'auto'
this.style.height = (this.scrollHeight) + 'px'
}

connect() {
connect(): void {
this.element.setAttribute('style', 'height:' + (this.element.scrollHeight) + 'px;overflow-y:hidden;')
this.element.addEventListener('input', this.onInput, false)
}
Expand Down
6 changes: 3 additions & 3 deletions playbook/app/pb_kits/playbook/pb_time/_time.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type TimeProps = {
unstyled?: boolean;
} & GlobalProps

const Time = (props: TimeProps) => {
const Time = (props: TimeProps): React.ReactElement => {
const {
align,
className,
Expand All @@ -47,8 +47,8 @@ const Time = (props: TimeProps) => {

return (
<div
{...htmlProps}
className={classes}
{...htmlProps}
className={classes}
>
{showIcon && (
unstyled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const dateTimeIso = (dateValue: Date) => {
return DateTime.toIso(dateValue)
}

const TimeRangeInline = (props: TimeRangeInlineProps) => {
const TimeRangeInline = (props: TimeRangeInlineProps): React.ReactElement => {
const {
aria = {},
className,
Expand Down
2 changes: 1 addition & 1 deletion playbook/app/pb_kits/playbook/pb_timeline/_item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const TimelineItem = ({
iconColor = 'default',
lineStyle = 'solid',
...props
}: ItemProps) => {
}: ItemProps): React.ReactElement => {
const timelineItemCss = buildCss('pb_timeline_item_kit', lineStyle)

const htmlProps = buildHtmlProps(htmlOptions)
Expand Down
2 changes: 1 addition & 1 deletion playbook/app/pb_kits/playbook/pb_timeline/_timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const Timeline = ({
orientation = 'horizontal',
showDate = false,
...props
}: TimelineProps) => {
}: TimelineProps): React.ReactElement => {
const ariaProps = buildAriaProps(aria)
const dataProps = buildDataProps(data)
const htmlProps = buildHtmlProps(htmlOptions)
Expand Down
20 changes: 10 additions & 10 deletions playbook/app/pb_kits/playbook/pb_title_detail/_title_detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type TitleDetailProps = {
title: string,
} & GlobalProps

const TitleDetail = (props: TitleDetailProps) => {
const TitleDetail = (props: TitleDetailProps): React.ReactElement => {
const {
align = "left",
aria = {},
Expand All @@ -37,19 +37,19 @@ const TitleDetail = (props: TitleDetailProps) => {

return (
<div
{...ariaProps}
{...dataProps}
{...htmlProps}
className={classnames(pbCss, globalProps(props), className)}
id={id}
{...ariaProps}
{...dataProps}
{...htmlProps}
className={classnames(pbCss, globalProps(props), className)}
id={id}
>
<Title
size={4}
text={title}
size={4}
text={title}
/>
<Body
color="light"
text={detail}
color="light"
text={detail}
/>
</div>
)
Expand Down
2 changes: 1 addition & 1 deletion playbook/app/pb_kits/playbook/pb_toggle/_toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const Toggle = ({
size = 'sm',
value,
...props
}: Props) => {
}: Props): React.ReactElement => {
const ariaProps = buildAriaProps(aria)
const dataProps = buildDataProps(data)
const htmlProps = buildHtmlProps(htmlOptions)
Expand Down
4 changes: 2 additions & 2 deletions playbook/app/pb_kits/playbook/pb_tooltip/_tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ const Tooltip = forwardRef((props: TooltipProps, ref: ForwardedRef<unknown>): Re
...rest
} = props

const dataProps: { [key: string]: any } = buildDataProps(data)
const ariaProps: { [key: string]: any } = buildAriaProps(aria)
const dataProps: { [key: string]: string } = buildDataProps(data)
const ariaProps: { [key: string]: string } = buildAriaProps(aria)
const htmlProps = buildHtmlProps(htmlOptions)

const css = classnames(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const TreemapChart = ({
tooltipHtml = '<span style="font-weight: bold; color:{point.color};">●</span>{point.name}: <b>{point.value}</b>',
type = "treemap",
...props
}: TreemapChartProps) => {
}: TreemapChartProps): React.ReactElement => {

const ariaProps = buildAriaProps(aria)
const dataProps = buildDataProps(data)
Expand Down Expand Up @@ -98,7 +98,6 @@ const TreemapChart = ({
const [options, setOptions] = useState({});

useEffect(() => {

setOptions(merge(staticOptions, customOptions));
}, [chartData]);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-console */

import React from 'react';
import { render, screen } from '../utilities/test-utils';
import TreemapChart from './_treemap_chart';
Expand Down
2 changes: 1 addition & 1 deletion playbook/app/pb_kits/playbook/pb_user/_user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type UserProps = {
title?: string,
} & GlobalProps

const User = (props: UserProps) => {
const User = (props: UserProps): React.ReactElement => {
const {
align = 'left',
aria = {},
Expand Down
Loading

0 comments on commit 3b54c73

Please sign in to comment.