Skip to content
Open
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
22 changes: 22 additions & 0 deletions packages/_helpers/affix.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,25 @@ export function Affix(props: AffixProps) {
</>,
);
}

interface IconAffixProps {
/** The icon SVG element */
children: React.ReactNode;

/** Affix added at the beginning of input */
prefix?: boolean;

/** Affix added at the end of input */
suffix?: boolean;
}

export function IconAffix(props: IconAffixProps) {
const classBase = props.prefix ? prefix : suffix;
const affixClass = `${classBase.wrapper} ${classBase.wrapperWithIcon}`;

return (
<div className={affixClass}>
<span className={classBase.label}>{props.children}</span>
</div>
);
}
2 changes: 1 addition & 1 deletion packages/_helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { Clickable } from './clickable';
export { DeadToggle } from './dead-toggle';
export { Affix } from './affix';
export { Affix, IconAffix } from './affix';
21 changes: 19 additions & 2 deletions packages/textfield/stories/Textfield.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import Search from '@fabric-ds/icons/react/search-16';
import { action } from '@storybook/addon-actions';
import React from 'react';
import { Affix, IconAffix } from '../../_helpers';
import { TextField as TroikaTextField } from '../src';
import { Affix } from '../../_helpers';

const metadata = { title: 'Forms/TextField' };
export default metadata;
Expand Down Expand Up @@ -50,6 +51,14 @@ export const labelPrefix = () => (
</TextField>
);

export const iconPrefix = () => (
<TextField>
<IconAffix prefix>
<Search />
</IconAffix>
</TextField>
);

export const clearSuffix = () => (
<TextField>
<Affix suffix clear onClick={() => alert('clear')} />
Expand All @@ -68,6 +77,14 @@ export const labelSuffix = () => (
</TextField>
);

export const iconSuffix = () => (
<TextField>
<IconAffix suffix>
<Search />
</IconAffix>
</TextField>
);

export const helpText = () => (
<TextField helpText="Necessary because of reasons" />
);
Expand Down