Skip to content

Commit

Permalink
feat: add asterisk component (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
josokinas authored Feb 17, 2021
1 parent 043d616 commit f9f9fb2
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
7 changes: 7 additions & 0 deletions packages/core/src/components/asterisk/asterisk.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@use '../../helpers';

@mixin Asterisk() {
.ods-asterisk {
color: helpers.color('content-negative');
}
}
3 changes: 3 additions & 0 deletions packages/core/src/components/index.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@use './includes';

@use './asterisk/asterisk';
@forward './asterisk/asterisk';
@use './button/button';
@forward './button/button';
@use './checkbox/checkbox';
Expand All @@ -24,6 +26,7 @@
@forward './validation/validation';

@mixin components() {
@include asterisk.Asterisk();
@include button.Button();
@include checkbox.Checkbox();
@include field.Field();
Expand Down
18 changes: 18 additions & 0 deletions packages/react/src/components/asterisk/asterisk.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { c, classy } from '@onfido/castor';
import React from 'react';

/**
* Use in `FieldLabel` to denote required fields.
*/
export const Asterisk = ({
className,
...restProps
}: AsteriskProps): JSX.Element => (
<abbr {...restProps} className={classy(c('asterisk'), className)}>
{' *'}
</abbr>
);

export type AsteriskProps = Omit<JSX.IntrinsicElements['abbr'], 'children'> & {
'aria-label': string;
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { color } from '@onfido/castor';
import {
Asterisk,
Field,
FieldLabel,
FieldLabelProps,
Expand Down Expand Up @@ -44,10 +45,8 @@ export const AsRequired: Story<FieldLabelProps> = ({
}: FieldLabelProps) => (
<FieldLabel {...restProps}>
<span>
{children}{' '}
<abbr aria-label="required" style={{ color: color('content-negative') }}>
*
</abbr>
{children}
<Asterisk aria-label="required" />
</span>
</FieldLabel>
);
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './asterisk/asterisk';
export * from './button/button';
export * from './checkbox/checkbox';
export * from './field-label/field-label';
Expand Down

0 comments on commit f9f9fb2

Please sign in to comment.