[next] Implement AriaInfo (#1756)

* Implement AriaInfo

* Fix build

* Default to div
This commit is contained in:
Kiwi
2018-07-20 23:17:47 +00:00
committed by Wyatt Johnson
parent afe816ba41
commit acb86f4b44
6 changed files with 83 additions and 0 deletions
@@ -0,0 +1,17 @@
---
name: AriaInfo
menu: UI Kit
---
import { Playground, PropsTable } from 'docz'
import AriaInfo from './AriaInfo'
# AriaInfo
Renders Text that is only seen by screen readers.
## Basic usage
<Playground>
<AriaInfo>This can only be seen by screen readers</AriaInfo>
<div>Above this line is a hidden text that you can't see</div>
</Playground>
@@ -0,0 +1,10 @@
.root {
position: absolute !important;
width: 1px;
height: 1px;
padding: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
@@ -0,0 +1,14 @@
import React from "react";
import TestRenderer from "react-test-renderer";
import { PropTypesOf } from "talk-framework/types";
import AriaInfo from "./AriaInfo";
it("renders correctly", () => {
const props: PropTypesOf<typeof AriaInfo> = {
children: "This text is only for screen readers",
};
const renderer = TestRenderer.create(<AriaInfo {...props} />);
expect(renderer.toJSON()).toMatchSnapshot();
});
@@ -0,0 +1,32 @@
import cn from "classnames";
import React, { HTMLAttributes, StatelessComponent } from "react";
import { withForwardRef, withStyles } from "talk-ui/hocs";
import { PropTypesOf } from "talk-ui/types";
import * as styles from "./AriaInfo.css";
interface InnerProps extends HTMLAttributes<HTMLElement> {
/**
* This prop can be used to add custom classnames.
* It is handled by the `withStyles `HOC.
*/
classes: typeof styles;
component?: string;
children: React.ReactNode;
}
const AriaInfo: StatelessComponent<InnerProps> = props => {
const { component, className, classes, ...rest } = props;
const Component = component!;
const rootClassName = cn(classes.root, className);
return <Component className={rootClassName} {...rest} />;
};
AriaInfo.defaultProps = {
component: "div",
};
const enhanced = withForwardRef(withStyles(styles)(AriaInfo));
export type AriaInfoProps = PropTypesOf<typeof enhanced>;
export default enhanced;
@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`renders correctly 1`] = `
<div
className="AriaInfo-root"
>
This text is only for screen readers
</div>
`;
@@ -0,0 +1 @@
export { default, AriaInfoProps } from "./AriaInfo";