Skip to content

Commit

Permalink
feat: add labs theme
Browse files Browse the repository at this point in the history
  • Loading branch information
shaneshen-okta committed Dec 14, 2022
1 parent 0434277 commit 8f45e5d
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 7 deletions.
2 changes: 2 additions & 0 deletions packages/odyssey-react-labs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ export type {
DatePickerProps,
LocalizationProviderProps,
} from "@mui/x-date-pickers";

export * from "./theme";
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*!
* Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved.
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
*
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and limitations under the License.
*/

import type {
ComponentsProps,
ComponentsOverrides,
ComponentsVariants,
Theme,
} from "@mui/material/styles";

declare module "@mui/material/styles" {
interface Components {
MuiPickersDay?: {
defaultProps?: ComponentsProps["MuiStepContent"];
styleOverrides?: ComponentsOverrides<Theme>["MuiStepContent"];
variants?: ComponentsVariants["MuiStepContent"];
};
PrivatePickersYear?: {
defaultProps?: ComponentsProps["MuiStepContent"];
styleOverrides?: ComponentsOverrides<Theme>["MuiStepContent"];
variants?: ComponentsVariants["MuiStepContent"];
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*!
* Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved.
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
*
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and limitations under the License.
*/

import type { ThemeOptions } from "@mui/material/styles";

export const datePickerTheme: ThemeOptions["components"] = {
MuiPickersDay: {
styleOverrides: {
root: ({ theme }) => ({
"&:focus, &:hover": {
backgroundColor: theme.palette.primary.main,
},
" &.Mui-selected:focus, &.Mui-selected:hover": {
backgroundColor: theme.palette.primary.main,
},
}),
},
},
PrivatePickersYear: {
styleOverrides: {
root: ({ theme }) => ({
"& > button:focus, & > button:hover": {
backgroundColor: theme.palette.primary.main,
},
" & > button.Mui-selected:focus, & > button.Mui-selected:hover": {
backgroundColor: theme.palette.primary.main,
},
}),
},
},
};
19 changes: 19 additions & 0 deletions packages/odyssey-react-labs/src/theme/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*!
* Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved.
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
*
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and limitations under the License.
*/

import type { ThemeOptions } from "@mui/material/styles";

import { datePickerTheme } from "./DatePicker/datePickerTheme";

export const components: ThemeOptions["components"] = {
...datePickerTheme,
};
13 changes: 13 additions & 0 deletions packages/odyssey-react-labs/src/theme/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*!
* Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved.
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
*
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and limitations under the License.
*/

export { theme as labsTheme } from "./theme";
19 changes: 19 additions & 0 deletions packages/odyssey-react-labs/src/theme/theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*!
* Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved.
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
*
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and limitations under the License.
*/

import type { ThemeOptions } from "@mui/material/styles";

import { components } from "./components";

export const theme: ThemeOptions = {
components,
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@

import React from "react";
import type { Story } from "@storybook/react";
import { InputBase, InputBaseProps } from "@okta/odyssey-react-mui";
import {
InputBase,
InputBaseProps,
OdysseyThemeProvider,
} from "@okta/odyssey-react-mui";
import {
AdapterDateFns,
DatePicker,
DatePickerProps,
LocalizationProvider,
} from "@okta/odyssey-react-labs";
import { MuiThemeDecorator } from "../../../../.storybook/components/MuiThemeDecorator";

import { labsTheme } from "../../../../../odyssey-react-labs/src";
import DatePickerMdx from "./DatePicker.mdx";

export default {
Expand Down Expand Up @@ -61,21 +65,22 @@ export default {
defaultValue: null,
},
},
decorators: [MuiThemeDecorator],
};

const Template: Story<DatePickerProps<unknown, unknown>> = (props) => {
const [value, setValue] = React.useState<unknown | null>(null);
const [value, setValue] = React.useState<unknown>(Date.now());
const datePickerProps = {
...props,
value,
onChange: (newValue: unknown) => setValue(newValue),
};

return (
<LocalizationProvider dateAdapter={AdapterDateFns}>
<DatePicker {...datePickerProps} />
</LocalizationProvider>
<OdysseyThemeProvider customTheme={labsTheme}>
<LocalizationProvider dateAdapter={AdapterDateFns}>
<DatePicker {...datePickerProps} />
</LocalizationProvider>
</OdysseyThemeProvider>
);
};

Expand Down

0 comments on commit 8f45e5d

Please sign in to comment.