Skip to content

Commit

Permalink
Add our wrapper elements for basic slots
Browse files Browse the repository at this point in the history
  • Loading branch information
snowystinger committed Dec 6, 2023
1 parent 178f0d4 commit d6bbb26
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 3 deletions.
34 changes: 34 additions & 0 deletions packages/@react-spectrum/s2/src/Heading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

import {DOMRef} from '@react-types/shared';
import {filterDOMProps} from '@react-aria/utils';
import {HeadingProps} from '@react-types/text';
import React, {ElementType, forwardRef} from 'react';
import {useDOMRef, useSlotProps, useStyleProps} from '@react-spectrum/utils';
import {Heading as RACHeading} from 'react-aria-components';

function Heading(props: HeadingProps, ref: DOMRef<HTMLHeadingElement>) {
props = useSlotProps(props, 'heading');

let {
children,
...otherProps
} = props;
let {styleProps} = useStyleProps(otherProps);
let domRef = useDOMRef(ref);

return (
<RACHeading
{...filterDOMProps(otherProps)}
{...styleProps}
level={props.level}
ref={domRef}>
{children}
</RACHeading>
);
}

/**
* Heading is used to create various levels of typographic hierarchies.
*/
const _Heading = forwardRef(Heading);
export {_Heading as Heading};
29 changes: 29 additions & 0 deletions packages/@react-spectrum/s2/src/Keyboard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

import {DOMRef} from '@react-types/shared';
import {filterDOMProps} from '@react-aria/utils';
import {KeyboardProps} from '@react-types/text';
import React, {forwardRef} from 'react';
import {useDOMRef, useSlotProps, useStyleProps} from '@react-spectrum/utils';
import {Keyboard as RACKeyboard} from 'react-aria-components';

function Keyboard(props: KeyboardProps, ref: DOMRef) {
props = useSlotProps(props, 'keyboard');
let {
children,
...otherProps
} = props;
let {styleProps} = useStyleProps(otherProps);
let domRef = useDOMRef(ref);

return (
<RACKeyboard {...filterDOMProps(otherProps)} {...styleProps} ref={domRef}>
{children}
</RACKeyboard>
);
}

/**
* Keyboard represents text that specifies a keyboard command.
*/
const _Keyboard = forwardRef(Keyboard);
export {_Keyboard as Keyboard};
16 changes: 13 additions & 3 deletions packages/@react-spectrum/s2/src/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,28 @@ import { useDOMRef, useSlotProps, useStyleProps } from "@react-spectrum/utils";
import {Text as RACText} from 'react-aria-components';
import {filterDOMProps} from "@react-aria/utils";
import { forwardRef } from "react";
import { TextProps } from "@adobe/react-spectrum";
import { DOMRef } from "@react-types/shared";

export let Text = forwardRef((props, ref) => {

function Text(props: TextProps, ref: DOMRef) {
props = useSlotProps(props, 'text');
let {
children,
...otherProps
} = props;
let {styleProps} = useStyleProps(otherProps);
let domRef = useDOMRef(ref);

return (
<RACText {...filterDOMProps(otherProps)} {...styleProps} ref={ref}>
<RACText {...filterDOMProps(otherProps)} {...styleProps} ref={domRef}>
{children}
</RACText>
);
});
}

/**
* Text represents text with no specific semantic meaning.
*/
const _Text = forwardRef(Text);
export {_Text as Text};

0 comments on commit d6bbb26

Please sign in to comment.