-
Notifications
You must be signed in to change notification settings - Fork 12
feat: enable to set theme for the scene #67
Conversation
✔️ Deploy Preview for reearth-web ready! 🔨 Explore the source changes: 4ff8efd 🔍 Inspect the deploy log: https://app.netlify.com/sites/reearth-web/deploys/613af9a8a19b930008e5fe5e 😎 Browse the preview: https://deploy-preview-67--reearth-web.netlify.app |
Codecov Report
@@ Coverage Diff @@
## main #67 +/- ##
==========================================
- Coverage 58.10% 57.46% -0.64%
==========================================
Files 40 44 +4
Lines 685 703 +18
Branches 96 104 +8
==========================================
+ Hits 398 404 +6
- Misses 245 257 +12
Partials 42 42
|
@lavalse , what about menu colors, should they stay dark? |
@issmail-basel For the menu widgets, because we will refine the logic in the future. So for now, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a somewhat roundabout implementation:
- Current: SceneProperty in Visualizer -up-> Global theme context -down-> Visualizer -down-> Each component (What was inside goes outside and then back inside again)
- Should be: Visualizer (SceneProperty) -down-> Each component
Since public themes are used only inside Visualizer, they do not depend on the global theme context (@reearth/theme
) and should be used by defining a premade theme inside Visualizer.
@@ -38,10 +38,12 @@ export type Props = { | |||
button: Button; | |||
menuItems?: MenuItem[]; | |||
pos: Position; | |||
sceneProperty?: any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sceneProperty?: any; | |
sceneProperty?: SceneProperty; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also needs the SceneProperty imported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still isn't resolved.
src/components/molecules/Visualizer/Widget/Storytelling/index.tsx
Outdated
Show resolved
Hide resolved
src/theme/publishTheme/hooks.ts
Outdated
export default (seneThemeOptions?: ReTheme) => { | ||
const [publishedTheme, setPublishedTheme] = useState<PublishTheme>(dark); | ||
function addAlpha(color?: string, opacity?: number): string { | ||
// coerce values so ti is between 0 and 1. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// coerce values so ti is between 0 and 1. | |
// coerce values so it is between 0 and 1. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still doesn't seem to be updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still not resolved
src/theme/publishTheme/hooks.ts
Outdated
themeBackgroundColor?: string; | ||
}; | ||
|
||
export default (seneThemeOptions?: ReTheme) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seneThemeOptions => sceneThemeOptions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not resolved
@@ -174,22 +194,23 @@ const Title = styled(Text)` | |||
} | |||
`; | |||
|
|||
const StyledIcon = styled(Icon)` | |||
color: ${props => props.theme.main.text}; | |||
const StyledIcon = styled(Icon)<{ publishedTheme: PublishTheme }>` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, one more thing. In components like this StyledIcon where all you are using is mainIcon from publishedTheme, can you pass JUST what you need, rather than the whole publishedTheme object.
In this case you could pass a color=publishedTheme.mainIcon
prop instead.
Please update other places where this applies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wasn't addressed. Please let me know if you don't catch what I mean and I can explain more!
@@ -160,7 +179,8 @@ const Current = styled(Flex)` | |||
} | |||
`; | |||
|
|||
const Title = styled(Text)` | |||
const Title = styled(Text)<{ color: string }>` | |||
color: ${({ color }) => color}!important; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The !important
isn't necessary. Above where you use Title just pass customColor
and you should be good to go!
ie
<Title color={publishedTheme.mainText} size="m" weight="bold" customColor>
....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one change requested and then LGTM! I'll approve but please make the change!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usePublicTheme
seems redundant, and I don't see the need to use Hooks. It's enough to simply have the following code:
@reearth/theme/public.ts
:
export type Theme = { themeBackgroundColor: string, /*...*/ };
export type ThemeType = "dark" | "light" | "forest";
export type ThemeConfig = Partial<Theme> & { type?: ThemeType | "custom" };
const defaultTheme: ThemeType = "dark";
const premade: {[key in ThemeType]: Theme } = {
dark: { ... },
light: { ... },
forest: { ... }
};
export function publicTheme(theme?: ThemeConfig): Theme {
return theme?.type === "custom"
? { ...premade[defaultTheme], ...theme }
: premade[theme?.type || defaultTheme];
}
Usage:
import { publicTheme } from "@reearth/theme";
function Storytelling({ sceneProperty }) {
const theme = publicTheme(sceneProperty?.theme);
// use theme!
}
This code doesn't use hooks so the code is very clean.
@rot1024 , thank you for your comment. |
It's strange. In my code, theme should be switched when sceneProperty is updated. Let me try my code in this PR. |
OK, and I tried and I understand hooks is needed because custom theme uses object and it's needed to prevent useless re-rendering. But there are rooms to be refactored so I did. Please check: scene-theme-front...scene-theme-front-refactor Points:
|
Co-authored-by: rot1024 <[email protected]>
* feat: tag system domain models (#39) * feat: tag system domain models * refactor: * add tag interface * tag -> group and tag->item conversation * testing: generate test cases for the tagID * resolve notes * fix unit tests errors * add NewId test code fix NewId func * add more test cases refactor some parts * feat: tag system data-layer (mongo) (#44) * feat: tag system data-layer (mongo) * remove len > 0 check * goimport * Update pkg/tag/group_builder.go Co-authored-by: rot1024 <[email protected]> * Update pkg/tag/item_builder.go Co-authored-by: rot1024 <[email protected]> * rename itemFrom and groupFrom funcs Co-authored-by: rot1024 <[email protected]> * feat: create tag group and tag item (#45) * tag item and group schema * feat: creat tags (GQL schema) * tag items and tag groups resolvers * datalayer (dummy memory) and usecases * receive list by reference * check if nil for list * resolve notes * generate new models * feat: memory infrastructure (#46) * refactor: implement memory infrastructure * test: implement memory infrastructure test cases * test: fix FindByScene test case * feat: attach/detach tag from layer (#50) * tag item and group schema * feat: creat tags (GQL schema) * tag items and tag groups resolvers * datalayer (dummy memory) and usecases * receive list by reference * check if nil for list * feat: introduce tags to layers * feat: attach/detach tags from layers * fix imports * refactor: resolve notes * test: test units for tags * refactor: resolve notes * feat: attach/detach tag item from group (#52) * refactor: transform group tags list to reference * feat: attach/detach tags * refactor: use params as use-case input * test: mongodoc testing (#61) * test: mongodoc testing * resolve notes * feat: remove tag (#58) * feat: remove a tag (init) * feat: remove tag * feat: remove tag usecase and infra * resolve notes * feat: tag system queries (#54) * feat: tag system queries * resolve notes * feat: update tag (#49) * tag item and group schema * feat: creat tags (GQL schema) * tag items and tag groups resolvers * datalayer (dummy memory) and usecases * receive list by reference * check if nil for list * feat: rename tag group * refactor: rename -> update * resolve notes * resolve notes * change find by id func return type * Merge branch 'tag-system' of https://github.com/reearth/reearth-backend into tag/update-group-label # Conflicts: # internal/adapter/gql/generated.go # internal/adapter/gql/gqlmodel/convert_tag.go * fix testing * resolve notes * resolve notes * resolve notes Co-authored-by: HideBa <[email protected]> Co-authored-by: rot1024 <[email protected]>
Overview
Add Scene theme option, users can define the basic theme which is used for all components on the scene.
What I've done
How I tested
Publish Theme
pre made theme
orcustom theme
with color preferencesEditor
,Preview page
andpublished project
Screenshot
Which point I want you to review particularly