Skip to content

Commit

Permalink
feat(chat-settings): add font-weight on chat theme settings
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineHbnt authored and WilliamTraoreee committed Sep 10, 2022
1 parent e0bcabb commit d979507
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 5 deletions.
2 changes: 2 additions & 0 deletions apps/app/src/app/pages/chatbox/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const defaultSettings: Omit<ChatTheme, 'user_id' | 'id'> | ChatTheme = {
name: {
fullWidth: false,
fontFamily: 'Rubik',
fontWeight: 'regular',
fontSize: '16',
textAlign: 'left' as 'left' | 'right' | 'center',
textColor: '#000000',
Expand All @@ -33,6 +34,7 @@ const defaultSettings: Omit<ChatTheme, 'user_id' | 'id'> | ChatTheme = {
message: {
fullWidth: false,
fontFamily: 'Rubik',
fontWeight: 'regular',
fontSize: '14',
textAlign: 'left' as 'left' | 'right' | 'center',
textColor: '#000000',
Expand Down
2 changes: 2 additions & 0 deletions libs/shared/schema/src/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const GlobalSchema = z.object({
export const NameChatSchema = z.object({
fullWidth: z.boolean(),
fontFamily: z.string(),
fontWeight: z.string(),
fontSize: z.string(),
textAlign: z.enum(['left', 'center', 'right']),
textColor: z.string(),
Expand Down Expand Up @@ -38,6 +39,7 @@ export const NameChatSchema = z.object({
export const MessageSchema = z.object({
fullWidth: z.boolean(),
fontFamily: z.string(),
fontWeight: z.string(),
fontSize: z.string(),
textAlign: z.enum(['left', 'center', 'right']),
textColor: z.string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export function ChatMessage(props: ChatMessageProps) {
setNameStyle({
width: settings.name.fullWidth ? '100%' : 'auto',
fontFamily: settings.name.fontFamily,
fontWeight: settings.name.fontWeight,
color: settings.name.textColor,
backgroundColor: settings.name.backgroundColor,
textAlign: settings.name.textAlign as 'left' | 'center' | 'right',
Expand All @@ -52,6 +53,7 @@ export function ChatMessage(props: ChatMessageProps) {
setMessageStyle({
width: settings.message.fullWidth ? '100%' : 'auto',
fontFamily: settings.message.fontFamily,
fontWeight: settings.message.fontWeight,
color: settings.message.textColor,
backgroundColor: settings.message.backgroundColor,
textAlign: settings.message.textAlign as 'left' | 'right' | 'center',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ const Template: ComponentStory<typeof ChatSettings> = (args) => (
);

export const Primary = Template.bind({});
Primary.args = {};
Primary.args = {
onSettingsChange: (settings) => console.log(settings),
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { useState } from 'react';
import { Control, Controller } from 'react-hook-form';
import Accordion from '../../accordion/accordion';
import AccordionItem from '../../accordion/accordion-item';
import Color from '../../forms/color/color';
import FontSelect from '../../forms/font-select/font-select';
import FontSelect, { fontVariants } from '../../forms/font-select/font-select';
import Select from '../../forms/select/select';
import Slider from '../../forms/slider/slider';
import Spacing from '../../forms/spacing/spacing';
import Switch from '../../forms/switch/switch';
Expand All @@ -14,6 +16,14 @@ export interface TabsGeneralProps {

function TabsMessage(props: TabsGeneralProps) {
const { control } = props;
const [fontVariants, setFontVariants] = useState<fontVariants[]>([
{ label: 'Thin', value: '100' },
{ label: 'Light', value: '300' },
{ label: 'Regular', value: 'regular' },
{ label: 'Medium', value: '500' },
{ label: 'Bold', value: '700' },
{ label: 'Black', value: '900' },
]);

return (
<div>
Expand All @@ -37,11 +47,33 @@ function TabsMessage(props: TabsGeneralProps) {
<FontSelect
label="Font (with Google Fonts)"
className="mb-3"
onChange={(fontName, variants) => onChange(fontName)}
onChange={(value) => onChange(value)}
defaultValue={{ value: value, label: value }}
/>
)}
/>
<Controller
name="message.fontWeight"
control={control}
defaultValue="regular"
render={({ field: { onChange, value } }) => (
<Select
label="Font weight"
options={fontVariants.map(({ label, value }) => {
return {
label: label[0].toUpperCase() + label.substring(1),
value: value,
};
})}
onChange={(value) => onChange(value?.value)}
defaultValue={{
label: value[0].toUpperCase() + value.substring(1),
value: value,
}}
className="mb-3"
/>
)}
/>
<Controller
name="message.fontSize"
control={control}
Expand Down
38 changes: 36 additions & 2 deletions libs/shared/ui/src/lib/components/chat/chat-settings/tabs-name.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useState } from 'react';
import { Control, Controller } from 'react-hook-form';
import Accordion from '../../accordion/accordion';
import AccordionItem from '../../accordion/accordion-item';
import Color from '../../forms/color/color';
import FontSelect from '../../forms/font-select/font-select';
import FontSelect, { fontVariants } from '../../forms/font-select/font-select';
import Select from '../../forms/select/select';
import Slider from '../../forms/slider/slider';
import Spacing from '../../forms/spacing/spacing';
Expand All @@ -15,6 +16,14 @@ export interface TabsGeneralProps {

function TabsName(props: TabsGeneralProps) {
const { control } = props;
const [fontVariants, setFontVariants] = useState<fontVariants[]>([
{ label: 'Thin', value: '100' },
{ label: 'Light', value: '300' },
{ label: 'Regular', value: 'regular' },
{ label: 'Medium', value: '500' },
{ label: 'Bold', value: '700' },
{ label: 'Black', value: '900' },
]);

return (
<div>
Expand Down Expand Up @@ -72,11 +81,36 @@ function TabsName(props: TabsGeneralProps) {
<FontSelect
label="Font (with Google Fonts)"
className="mb-3"
onChange={(fontName, variants) => onChange(fontName)}
onChange={(fontName, variants) => {
setFontVariants(variants);
onChange(fontName);
}}
defaultValue={{ label: value, value: value }}
/>
)}
/>
<Controller
name="name.fontWeight"
control={control}
defaultValue="regular"
render={({ field: { onChange, value } }) => (
<Select
label="Font weight"
options={fontVariants.map(({ label, value }) => {
return {
label: label[0].toUpperCase() + label.substring(1),
value: value,
};
})}
onChange={(value) => onChange(value?.value)}
defaultValue={{
label: value[0].toUpperCase() + value.substring(1),
value: value,
}}
className="mb-3"
/>
)}
/>
<Controller
name="name.fontSize"
control={control}
Expand Down

0 comments on commit d979507

Please sign in to comment.