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

feat: adding fullWidth version of RichTextField #966

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 17 additions & 0 deletions src/inputs/RichTextField.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,20 @@ export function ToggleReadOnly() {
</>
);
}

export function FullWidth() {
const value =
"<div><!--block-->This is some content<br><br></div><ul><li><!--block-->this is a bullet</li><li><!--block--><em>another bullet here</em></li></ul><div><!--block--><br><strong>some really important content</strong></div>";

return (
<RichTextFieldComponent
label="Comment"
value={value}
onChange={noop}
fullWidth
placeholder="Enter Text"
onBlur={noop}
onFocus={noop}
/>
);
}
8 changes: 5 additions & 3 deletions src/inputs/RichTextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export interface RichTextFieldProps {
onFocus?: () => void;
/** For rendering formatted text */
readOnly?: boolean;
/** Will set width to: 100% */
fullWidth?: boolean;
}

/**
Expand All @@ -38,7 +40,7 @@ export interface RichTextFieldProps {
* We also integrate [tributejs]{@link https://github.com/zurb/tribute} for @ mentions.
*/
export function RichTextField(props: RichTextFieldProps) {
const { mergeTags, label, value = "", onChange, onBlur = noop, onFocus = noop, readOnly } = props;
const { mergeTags, label, value = "", onChange, onBlur = noop, onFocus = noop, readOnly, fullWidth } = props;

// We get a reference to the Editor instance after trix-init fires
const [editor, setEditor] = useState<Editor>();
Expand Down Expand Up @@ -129,7 +131,7 @@ export function RichTextField(props: RichTextFieldProps) {

if (!readOnly) {
return (
<div css={Css.w100.maxw("550px").$}>
<div css={Css.w100.if(!fullWidth).maxw("550px").$}>
{/* TODO: Not sure what to pass to labelProps. */}
{label && <Label labelProps={{}} label={label} />}
<div css={{ ...Css.br4.bgWhite.$, ...trixCssOverrides }}>
Expand All @@ -148,7 +150,7 @@ export function RichTextField(props: RichTextFieldProps) {
);
} else {
return (
<div css={Css.w100.maxw("550px").$}>
<div css={Css.w100.if(!fullWidth).maxw("550px").$}>
{label && <Label label={label} />}
<div
css={Css.mh("120px").bgWhite.sm.gray900.bn.p1.br4.bGray300.ba.$}
Expand Down
Loading