mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-24 19:39:11 +00:00
feat(editor): add permalink section in editor
This commit is contained in:
parent
f86eaae5e9
commit
0d96a4f973
11 changed files with 125 additions and 2 deletions
11
packages/design-system/atoms/copy-area/CopyArea.stories.tsx
Normal file
11
packages/design-system/atoms/copy-area/CopyArea.stories.tsx
Normal file
|
@ -0,0 +1,11 @@
|
|||
import { CopyArea } from './CopyArea';
|
||||
|
||||
export default {
|
||||
title: 'Atoms/Copy Area',
|
||||
component: CopyArea,
|
||||
args: {
|
||||
value: 'Hello world',
|
||||
},
|
||||
};
|
||||
|
||||
export const copyArea = (args) => <CopyArea {...args} />;
|
19
packages/design-system/atoms/copy-area/CopyArea.styled.ts
Normal file
19
packages/design-system/atoms/copy-area/CopyArea.styled.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { palette } from '@roleypoly/design-system/atoms/colors';
|
||||
import { StyledTextInput } from '@roleypoly/design-system/atoms/text-input';
|
||||
import styled, { css } from 'styled-components';
|
||||
|
||||
export const CopyAreaStyled = styled.div`
|
||||
cursor: pointer;
|
||||
`;
|
||||
|
||||
export const CopyAreaTextInput = styled(StyledTextInput)<{ copied?: boolean }>`
|
||||
margin: 0.5em 0;
|
||||
cursor: pointer;
|
||||
font-size: 1em;
|
||||
${({ copied }) =>
|
||||
copied &&
|
||||
css`
|
||||
border-color: ${palette.green400} !important;
|
||||
box-shadow: inset 0 0 2px ${palette.green200} !important;
|
||||
`}
|
||||
`;
|
47
packages/design-system/atoms/copy-area/CopyArea.tsx
Normal file
47
packages/design-system/atoms/copy-area/CopyArea.tsx
Normal file
|
@ -0,0 +1,47 @@
|
|||
import React from 'react';
|
||||
import ReactTooltip from 'react-tooltip';
|
||||
import { CopyAreaStyled, CopyAreaTextInput } from './CopyArea.styled';
|
||||
|
||||
type CopyAreaProps = {
|
||||
value: string;
|
||||
};
|
||||
|
||||
enum CopyState {
|
||||
NotCopied = 0,
|
||||
Copied = 1,
|
||||
}
|
||||
|
||||
export const CopyArea = (props: CopyAreaProps) => {
|
||||
const [copied, setCopied] = React.useState<CopyState>(CopyState.NotCopied);
|
||||
|
||||
const inputRef = React.useRef<HTMLInputElement>(null);
|
||||
|
||||
const handleClick = () => {
|
||||
inputRef.current?.setSelectionRange(0, 99999);
|
||||
|
||||
if (navigator.clipboard) {
|
||||
navigator.clipboard.writeText(props.value);
|
||||
setCopied(CopyState.Copied);
|
||||
}
|
||||
};
|
||||
|
||||
const strings = {
|
||||
[CopyState.NotCopied]: `Press ⌘/Ctrl+C to copy`,
|
||||
[CopyState.Copied]: 'Copied to clipboard!',
|
||||
};
|
||||
|
||||
return (
|
||||
<CopyAreaStyled>
|
||||
<CopyAreaTextInput
|
||||
ref={inputRef}
|
||||
value={props.value}
|
||||
onClick={handleClick}
|
||||
onBlur={() => setCopied(CopyState.NotCopied)}
|
||||
copied={copied === CopyState.Copied}
|
||||
data-tip={strings[copied]}
|
||||
data-for={'copy-area'}
|
||||
/>
|
||||
<ReactTooltip id="copy-area" />
|
||||
</CopyAreaStyled>
|
||||
);
|
||||
};
|
1
packages/design-system/atoms/copy-area/index.ts
Normal file
1
packages/design-system/atoms/copy-area/index.ts
Normal file
|
@ -0,0 +1 @@
|
|||
export * from './CopyArea';
|
|
@ -40,7 +40,7 @@ const common = css`
|
|||
}
|
||||
`;
|
||||
|
||||
const StyledTextInput = styled.input`
|
||||
export const StyledTextInput = styled.input`
|
||||
${common};
|
||||
`;
|
||||
|
||||
|
@ -89,6 +89,7 @@ export const TextInputWithIcon = (props: TextInputWithIconProps) => {
|
|||
const StyledTextarea = styled.textarea`
|
||||
${common};
|
||||
${fontCSS};
|
||||
margin: 0.5em 0;
|
||||
`;
|
||||
|
||||
export const MultilineTextInput = (
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
import { mastheadSlugs } from '../../fixtures/storyData';
|
||||
import { EditorInviteLink } from './EditorInviteLink';
|
||||
|
||||
export default {
|
||||
title: 'Molecules/Editor Invite Link',
|
||||
component: EditorInviteLink,
|
||||
args: {
|
||||
guild: mastheadSlugs[0],
|
||||
},
|
||||
};
|
||||
|
||||
export const editorInviteLink = (args) => <EditorInviteLink {...args} />;
|
|
@ -0,0 +1,2 @@
|
|||
import styled from 'styled-components';
|
||||
export const EditorInviteLinkStyled = styled.div``;
|
|
@ -0,0 +1,26 @@
|
|||
import { palette } from '@roleypoly/design-system/atoms/colors';
|
||||
import { CopyArea } from '@roleypoly/design-system/atoms/copy-area';
|
||||
import { AmbientLarge } from '@roleypoly/design-system/atoms/typography';
|
||||
import { MessageBox } from '@roleypoly/design-system/organisms/role-picker/RolePicker.styled';
|
||||
import { Guild } from '@roleypoly/types';
|
||||
import { GoInfo } from 'react-icons/go';
|
||||
|
||||
export const EditorInviteLink = (props: { guild: Guild }) => {
|
||||
const currentURL = new URL(location.href);
|
||||
currentURL.pathname = `/s/${props.guild.id}`;
|
||||
currentURL.search = '';
|
||||
|
||||
const inviteLink = currentURL.toString();
|
||||
|
||||
return (
|
||||
<MessageBox>
|
||||
Share this link with your server members, or ping{' '}
|
||||
<span style={{ color: palette.taupe500 }}>@roleypoly</span> in your server.
|
||||
<CopyArea value={inviteLink} />
|
||||
<AmbientLarge style={{ display: 'flex', color: palette.taupe600 }}>
|
||||
<GoInfo style={{ position: 'relative', top: 4 }} />
|
||||
This link will never change. Share it with anyone!
|
||||
</AmbientLarge>
|
||||
</MessageBox>
|
||||
);
|
||||
};
|
|
@ -0,0 +1 @@
|
|||
export * from './EditorInviteLink';
|
|
@ -1,5 +1,6 @@
|
|||
import { LinedSpace, Space } from '@roleypoly/design-system/atoms/space';
|
||||
import { EditableServerMessage } from '@roleypoly/design-system/molecules/editable-server-message';
|
||||
import { EditorInviteLink } from '@roleypoly/design-system/molecules/editor-invite-link';
|
||||
import { ServerMasthead } from '@roleypoly/design-system/molecules/server-masthead';
|
||||
import { ServerUtilities } from '@roleypoly/design-system/molecules/server-utilities/ServerUtilities';
|
||||
import { SecondaryEditing } from '@roleypoly/design-system/organisms/masthead';
|
||||
|
@ -60,6 +61,8 @@ export const EditorShell = (props: EditorShellProps) => {
|
|||
<Space />
|
||||
<ServerMasthead guild={props.guild.guild} editable={false} />
|
||||
<Space />
|
||||
<EditorInviteLink guild={props.guild.guild} />
|
||||
<Space />
|
||||
<EditableServerMessage
|
||||
onChange={onMessageChange}
|
||||
value={guild.data.message}
|
||||
|
|
|
@ -14,7 +14,7 @@ const ServersPage = () => {
|
|||
|
||||
return (
|
||||
<>
|
||||
<Title title={'Your Guilds - Roleypoly'} />
|
||||
<Title title={'Your Servers - Roleypoly'} />
|
||||
<ServersTemplate {...appShellProps} />
|
||||
</>
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue