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

Add callbacks #914

Merged
merged 2 commits into from
Nov 23, 2022
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
5 changes: 5 additions & 0 deletions .changeset/beige-fishes-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@web3uikit/core": patch
---

Add callbacks to credentials
4 changes: 4 additions & 0 deletions packages/core/src/lib/Credentials/Credentials.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { Credentials } from '.';
export default {
title: '2.Forms/Credentials',
component: Credentials,
argTypes: {
onCopy: { action: 'clicked' },
onReveal: { action: 'revealed' },
},
} as ComponentMeta<typeof Credentials>;

const Template: ComponentStory<typeof Credentials> = (args) => (
Expand Down
11 changes: 9 additions & 2 deletions packages/core/src/lib/Credentials/Credentials.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const Credentials: FC<ICredentialsProps> = ({
title,
titleColor,
width = 'auto',
onCopy,
onReveal,
...props
}) => {
const [isValueHidden, setIsValueHidden] = useState(isHidden);
Expand Down Expand Up @@ -81,12 +83,17 @@ const Credentials: FC<ICredentialsProps> = ({
<ToolsStyled data-testid="test-credentials-tools">
{hasHideButton && (
<HideButton
onToggle={() => setIsValueHidden(!isValueHidden)}
onToggle={() => {
setIsValueHidden(!isValueHidden);
if (isValueHidden) onReveal && onReveal();
}}
isHidden={isValueHidden}
/>
)}
{hasHideButton && hasCopyButton && <DividerStyled />}
{hasCopyButton && <CopyButton text={text} iconSize={24} />}
{hasCopyButton && (
<CopyButton text={text} iconSize={24} onCopy={onCopy} />
)}
</ToolsStyled>
</PreformattedStyled>
</CredentialsStyled>
Expand Down
12 changes: 11 additions & 1 deletion packages/core/src/lib/Credentials/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { color } from '@web3uikit/styles';
import React from 'react';
import { Typography } from '../Typography';
import { CopyButtonProps } from '../CopyButton';

export interface ICredentialsProps extends ICredentialsHeaderProps {
type TCopyButtonProps = Pick<CopyButtonProps, 'onCopy'>;

export interface ICredentialsProps
extends ICredentialsHeaderProps,
TCopyButtonProps {
/**
* if true displays Copy Button
*/
Expand Down Expand Up @@ -39,6 +44,11 @@ export interface ICredentialsProps extends ICredentialsHeaderProps {
* default is "auto"
*/
width?: string;

/**
* This event will fire when hideButton clicked to reveal hidden text only
*/
onReveal?: () => void;
}
export interface ICredentialsHeaderProps {
/**
Expand Down